jQueryUI accordion with checkboxes

99封情书 提交于 2019-12-18 05:50:49

问题


I'm trying to put a checkbox in each of my accordion headings to indicate whether something should be disabled or not. The checkbox shows up fine, however, its not clickable as the whole accordion header is linked to the <a> tag. Putting the checkbox outside the <a> tag makes the checkbox appear underneath the heading, which is not what I want, and it still isn't clickable either.

<div id="accordion">
    <h3><a href="#">Text <span id="id">More text<input type="checkbox"/></span></a></h3>
    <div>content etc</div>
</div>

回答1:


You can use stopPropagation() to fix this

example jsfiddle

something like

$('#accordion input[type="checkbox"]').click(function(e) {
    e.stopPropagation();
});



回答2:


I would be taking the input control out of the hyperlink.

<h3><a href="#">Text</a><span id="id">More text<input type="checkbox"/></span></h3>



回答3:


<input type="checkbox" onclick="event.stopPropagation()" />



回答4:


Try setting the checkbox to checked in the acordion click event, using

<input type="checkbox" name="foo" />

in the html and

$('input[name=foo]').attr('checked', true);

in the event.



来源:https://stackoverflow.com/questions/7426425/jqueryui-accordion-with-checkboxes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!