【发布时间】:2016-11-14 09:25:43
【问题描述】:
我知道有很多主题可以通过单击 href 来检查复选框,但在我看到的每个解决方案中,您无法通过单击复选框来检查复选框,因为它被 <a> 标记包裹。
这是我的html:
<a href='#' id='cb'>mode<input type='checkbox' id='mode'></a>
我的 Jquery:
$("#cb").click(function(e) {
e.preventDefault();
$("#mode").prop("checked", !$("#mode").prop("checked"));
})
我需要什么:
我需要能够通过单击 href 和单击复选框来选中复选框。
如果这篇文章是重复的,我很抱歉,但我没有看到它,把重复的链接给我,我会删除它。
【问题讨论】:
-
为什么需要锚点内的复选框?
-
你可以试试
$("#mode").click(function(e){ e.stopPropagation(); });jsfiddle.net/fwzd08cw/3
标签: javascript jquery html checkbox