如何正确解开元素?

这是我的绑定代码:

  function($){ $.event.special.destroyed = { remove: function(o) { if (o.handler) { o.handler() } } } })(jQuery); $("#exam-passing-test").on("destroyed", function() { console.log("bind") alert("Error"); }); $("#button-next-task").on("click", function(e){ e.preventDefault(); $("#exam-passing-test").off("destroyed", function() { console.log("unbindOk") }); $("#content-exam").load("/exam.php?action=show&epage=task&categoryId=" + selectedCategoryId, {testData:testData}); )}; 

好的,现在我只是尝试这样做,我简化了代码,但仍然没有工作。 点击按钮需要off()事件。

考虑使用jQuery.one()方法:

 $( "#exam-passing-test" ).one( "click", function( event ) { alert( "A click event happened!" ); }); 

它只会处理您的click事件一次。