Jquery删除元素内的所有事件处理程序 [英] Jquery Remove All Event Handlers Inside Element
本文介绍了Jquery删除元素内的所有事件处理程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
$(#button1)。off()
要删除按钮的处理程序,但如果可能,我想做这样的事情:
$(#div1)。removeChildHandlers();
JQuery中是否有本机功能来执行此操作,或者我必须将所有元素和删除1 by 1?
解决方案
jQuery将为您的直接孩子做循环:
$(#div1)。children()。
或如果您想要所有后代:
$( #DIV1)找到( *)关闭()。。
I have a div element with several elements inside it like buttons and so forth which have event handlers attached to them. I know its possible to go:
$("#button1").off()
To remove the handler for a button but I would like to do something like this if possible:
$("#div1").removeChildHandlers();
Is there a native function in JQuery to do this or would I have to loop them all the elements and remove 1 by 1?
解决方案
jQuery will do the looping for you for just the direct children:
$("#div1").children().off();
or if you want all descendants:
$("#div1").find("*").off();
这篇关于Jquery删除元素内的所有事件处理程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文