美文网首页
单选框、复选框

单选框、复选框

作者: _信仰zmh | 来源:发表于2017-12-19 22:18 被阅读0次
1. label标签

<label> 标签为 input 元素定义 标注(标记)

label 元素不会向用户呈现任何特殊效果。不过,它为鼠标用户改进了可用性

如果您在 label 元素内点击文本,就会触发此控件。就是说,当用户选择该标签时,浏览器就会自动将焦点转到和标签相关的表单控件上。

<label> 标签的 for 属性应当与相关元素的 id 属性相同。

2.单选框
  • input设置typeradio
  • 多个选择项,设置 同一name
  • value 属性,用于传值
  • idlabel中的 for属性值一致
  • checked 用于默认选中
<form>
性别:
  <input type="radio" name="sex" value="boy" id="inputIdName1" />
  <label for="inputIdName1">男</label>
  <input type="radio" name="sex" value="girl"  id="inputIdName2" />
  <label for="inputIdName2">女</label>
</form>

3. 复选框
  • type为checkbox
  • name不唯一
<form>
你喜欢哪些水果?
<br/>
<input type="checkbox" name="apple">苹果
<input type="checkbox" name="banana">香蕉
<input type="checkbox" name="pear">梨子
</form>

相关文章

网友评论

      本文标题:单选框、复选框

      本文链接:https://www.haomeiwen.com/subject/uehiwxtx.html