[英]How to unbind all events from custom object?
问题在于此对象的选择器可能不同。
$('body').on('submit','form',function(){});
$('.container').on('submit','form',function(){});
$('.container').on('submit','#myform',function(){});
而且我不知道如何解开所有这些事件。 我可以使用off(); 功能
但是对于每个选择器我都无法做到; 因为选择器很多 我如何从#myform中删除每个事件?
你可以做:
$("#myform").children().off();
或者您也可以使用*
:
$("#myform *").off();
由于您还想处理委托处理程序
$("#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.