如何使单击文本标签的复选框切换? [英] How do I make a checkbox toggle from clicking on the text label as well?

查看:155
本文介绍了如何使单击文本标签的复选框切换?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

html表单中的复选框没有隐含的标签。在其旁边添加显式标签(某些文字)不会切换复选框。

Checkboxes in html forms don't have implicit labels with them. Adding an explicit label (some text) next to it doesn't toggle the checkbox.

推荐答案

设置CSSdisplay

Set the CSS "display" property for the label to be a block element and use that instead of your div - it keeps the semantic meaning of a label while allowing whatever styling you like.

例如,

<label for="test" style="width: 100px; height: 100px; display: block; background-color: #e0e0ff;">
    A ticky box! <input type="checkbox" id="test" />
</label>

这篇关于如何使单击文本标签的复选框切换?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆