看到别人写的简洁明了,收藏一下
原文地址:https://zhidao.baidu.com/question/311244389.html
label标签主要是方便鼠标点击使用,增强用户操作体验。
1、新建html文件,在网页中设置一个性别选项,这时当用户点击性别后面的小圆点才能选择性别,由于小圆点区域比较小,想准确点击比较麻烦,所有用户体验不好:
2、为两个选项分别设置“id”属性,男性属性值为“male”,女性属性值为“female”:
3、为“男”和“女”文字都添加上“label”标签,标签属性“for”的属性值分别为“male”和“female”,这时用户点击“男”和“女”文字时也会选中对应的选项,提高了用户体验。除了单选框之外,多选框、文本框等标签也同样可以用label标签选中: