首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在html中创建6个复选框

在html中创建6个复选框
EN

Stack Overflow用户
提问于 2014-11-03 10:04:54
回答 1查看 184关注 0票数 2

如何创建6个如下所示的复选框?我知道如何隐藏复选框,但我如何才能使其成为可以单击文本的复选框?

代码语言:javascript
复制
<tr>
<td class = "first">Select Folder(s)</td>
<td class = "second">
<input id="hw" type="checkbox">hw1
  <input id="hw" type="checkbox">hw2
     <input id="hw" type="checkbox">hw3
        <input id="hw" type="checkbox">hw4
           <input id="hw" type="checkbox">hw5
              <input id="hw" type="checkbox">hw6
</td>

应该是这样的:

选择文件夹| (hw1) (hw2) .....

硬件复选框应该是可点击的,并且我需要能够选择多个。

EN

回答 1

Stack Overflow用户

发布于 2014-11-03 10:14:02

我认为您需要<label> HTML标记。指定<label,然后指定for=",然后指定要将其附加到的元素的id (单选按钮或复选框)。最后,它应该看起来像这样:

<label for="hw">text that they can click on goes here</label>

正如@tieTYT在注释中所述,另一种方法是将<label>标记包装在单选或复选框元素周围,如下所示:

<label><input type="radio"/>Text for the label here</label>

注意:对于旧的和有错误的IE浏览器,您可能仍然需要添加for=属性。

以下是您的最终代码(我在<label>s中添加了CSS属性cursor:pointer; ):

代码语言:javascript
复制
label {
  cursor: pointer;
}
input[type=checkbox] {
  cursor: pointer;
}
代码语言:javascript
复制
<tr>
  <td class="first">Select Folder(s)</td>
  <td class="second">
    <input id="hw" type="checkbox">
    <label for="hw">hw1</label>
    <input id="hw2" type="checkbox">
    <label for="hw2">hw2</label>
    <input id="hw3" type="checkbox">
    <label for="hw3">hw3</label>
    <input id="hw4" type="checkbox">
    <label for="hw4">hw4</label>
    <input id="hw5" type="checkbox">
    <label for="hw5">hw5</label>
    <input id="hw6" type="checkbox">
    <label for="hw6">hw6</label>
  </td>

希望这能有所帮助!

票数 9
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26706773

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档