jQuery .on单击第二次不起作用 [英] jQuery .on Click second time not working
本文介绍了jQuery .on单击第二次不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
var elms = $('.selector', list);
elms.off();
elms.on('vclick', function(event, ui) {
event.preventDefault();
var elm = $(this);
customEventHandler(elm, elm.attr("id"));
});
如果我通过$('.selector', list).on('click',...)
将click事件绑定到列表中的某个元素,则它工作正常.
If I bind the click event via $('.selector', list).on('click',...)
to an element in a list, it is working fine.
如果在将.append()
添加到列表并再次调用$('.selector', list).on('click',...)
之后添加元素,则不会触发单击.即使我之前使用.off()
删除了旧事件.
If I add elements after doing .append()
to the list and calling again $('.selector', list).on('click',...)
no click is triggered. Even if I use .off()
before to remove old events.
有什么想法或建议吗?
推荐答案
最后发现了问题,我必须在调用list.trigger("create");之后绑定事件.而不是以前,这可能对任何人都有用...
Finally found the problem, I had to bind the events after calling list.trigger("create"); instead of before, maybe this is helpful for anyone...
这篇关于jQuery .on单击第二次不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文