&LT a取代;标签内< label>标签不触发复选框 [英] <a> tag inside <label> tag not triggering checkbox

查看:100
本文介绍了&LT a取代;标签内< label>标签不触发复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须在< 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> $。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 on a and area elements is not required

这篇关于&LT a取代;标签内&lt; label&gt;标签不触发复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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