如果我像这样使用 .ajaxStop 附加事件处理程序:
$(document).ajaxStop(function() {
//Some code
});
如何删除该事件处理程序?
如果我像这样使用 .ajaxStop 附加事件处理程序:
$(document).ajaxStop(function() {
//Some code
});
如何删除该事件处理程序?
Try unbinding it, like so:
$(document).ajaxStop(function () {
$(this).unbind("ajaxStop");
//Some code
});
It's how I've been doing it.
如果您需要确保 ajaxStop() 方法中的处理程序代码在被删除之前执行,我建议如下:
$(document).ajaxStop(function(){
// Functions there
$(this).unbind("ajaxStop");
});
如果您在同一页面中有各种可能的 $.ajax 并且您想控制在何处执行 ajaxStop() 代码,则特别有用。然后,您只需在所需的 jQuery 函数中使用此代码。