< a取代;标签内< label>标签不触发复选框 [英] <a> tag inside <label> tag not triggering checkbox
问题描述
我必须在< label>
标记内使用< a>
。因为有很多css样式只适用于我们当前系统中的< a>
。 < a>
标记不会链接到任何页面,而是用于样式化/悬停。
I have to use <a>
inside a <label>
tag. Because there are many css styles only apply to <a>
in our current system. The <a>
tag is not linking to any pages but for styling/hovering.
请参阅以下代码:
<input type="checkbox" id="my-id">
<label for="my-id"><a href="javascript:void(0)">Some text</a></label>
但是当点击某些文字时,它不会切换复选框状态。
But when clicking on "Some text", it doesn't toggle the checkbox status.
我在< a> $ c上试过
$。preventDefault()
$ c>标签但不起作用。
I've tried $.preventDefault()
on the <a>
tag but doesn't work.
我该怎么做才能使< a>
表现出色喜欢标签吗?
What should i do to make the <a>
behaves like a label?
推荐答案
如果从中移除 href
属性一个
元素,点击文本将切换复选框。
If you remove the href
attribute from the a
element, clicking on the text will toggle the checkbox.
<input type="checkbox" id="my-id">
<label for="my-id"><a>Some text</a></label>
HTML规范状态:
href
属性a
和区域
元素不是必需的
The
href
attribute ona
andarea
elements is not required
这篇关于< a取代;标签内< label>标签不触发复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!