[英]How to unbind all events from custom object?
The problem is that the selectors for this object can be different. 问题在于此对象的选择器可能不同。
$('body').on('submit','form',function(){});
$('.container').on('submit','form',function(){});
$('.container').on('submit','#myform',function(){});
And i don't know how to unbind all this events. 而且我不知道如何解开所有这些事件。 I can use off();
我可以使用off(); function
功能
But for each selector i can't; 但是对于每个选择器我都无法做到; because there are a large number of selectors;
因为选择器很多 How i can remove each event from #myform?
我如何从#myform中删除每个事件?
You can do: 你可以做:
$("#myform").children().off();
or you can also use *
: 或者您也可以使用
*
:
$("#myform *").off();
Since you want to handle delegated handlers also 由于您还想处理委托处理程序
$("#myform").off('submit');//remove the submit handlers attached to the form
$("#myform").parents().off('submit', '#myform');//remove all submit delegated handlers registered to ancestor elements
//this is dangerous because it could remove common handlers
$("#myform").parents().off('submit', 'form');//but I don't think there is another easy way
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.