我得到了一个在accordion标题中带有<input>的jQuery accordion。手风琴是“可折叠的”,但我不希望在<input>中单击时展开(或折叠)该项目。
如何停止通过<input>元素冒泡的click事件,以避免激活accordion元素?
有没有什么聪明的方法可以将event.stopPropagation(); (或类似的东西)应用到accordions beforeActivate-callback?或者这可以直接在<input>的数据绑定上完成?
在我的bindingHandler上:
$(element).accordion({
header: ".accordion-header",
collapsible: true,
navigation: true,
heightStyle: "content",
active: false,
beforeActivate: function (event, ui) {
active = $(this).accordion("option", "active");
},
activate: function (event, ui) {
event.stopPropagation(); // This obviously has no effect
}
})发布于 2015-06-02 03:16:04
你这样做是对的,.stopPropagation()是正确的,你只是没有把它放在正确的位置,它会进入输入的点击处理程序。
例如。
$(document).on('click', '.my-input', function(e){
e.preventDefault(); // throw this in for good measures too
e.stopPropigation();
// your code to handle click here
});HTML
<input data-bind="click: clickHandler" />淘汰赛:
clickHandler = function(e){
e.preventDefault(); // throw this in for good measures too
e.stopPropigation();
};https://stackoverflow.com/questions/30581391
复制相似问题