html单选框和复选框

html单选框和复选框,第1张

单选这样写:<input ID="apple" name="fruit" type="radio" value ="Apple" /><Label for="apple">苹果</Label>

复选:

<input type="checkbox" name="fruit" value ="apple" ID="apple"><Label for="apple">苹果</Label>

如果多项的话,就直接for同样的ID,然后至少“苹果”变了文字而已,这个就是最好的方法了,没其他好的办法了

单选表单的话,表示这一组选项的input的type设置为radio且name值必须一致:

将input标签置于label中,点击label的时候会自动选择里面的input;

input与label是独立分开的,关联两者的是input的id值和label的for值;两者一致的时候,点击label相当于触发关联的input,两者不相邻依然有效;

例子:

12345678<form action="">

<input id="fruit1" type="radio" name="fruit" value="苹果" />

<label for="fruit1">苹果</label>

<input id="fruit2" type="radio" name="fruit" value="香蕉" />

<label for="fruit2">香蕉</label>

<input id="fruit3" type="radio" name="fruit" value="橘子" />

<label for="fruit3">橘子</label>

</form>


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/7004166.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-03-31
下一篇2023-03-31

发表评论

登录后才能评论

评论列表(0条)

    保存