如何创建复选框作为可点击标签?

问题描述

如何在HTML中创建带有文本框的可点击标签(单击标签或texbox会打开复选框)?

解决方法

请尝试

<label class="checklabel">Check Now
  <input type="checkbox">
</label>

,

如果我对您的理解正确,则可以执行以下操作:

<!DOCTYPE html>
<html>
<body>

<h1>Check Boxes - Example</h1>

<form action="/myPage.php">
  <input type="checkbox" id="chkboxQuestion" name="chkboxQuestion" value="Bike">
  <label for="chkboxQuestion">Do you like this checkbox?</label><br>
</form>

</body>
</html>

希望对您有所帮助!

,

如果我理解正确,那么您想检查是否单击了输入,并且必须在此输入上实现js

const other = document.getElementById("other");
const checkBox = document.getElementById("otherCheckbox")
other.addEventListener("click",() =>{
  if(checkBox.checked){
    checkBox.checked = false;
  }else{
    checkBox.checked = true;
  }
})
<input type="checkbox" name="color" id="otherCheckbox">
<label for="other">Other</label><input type="text" id="other">

,我更改了将“ otherCheckbox”的ID添加到复选框输入的html 就是这样,每次您单击输入时,输入都会切换支票

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...