This article will introduce the live binding events and unbinding methods in jQuery. I hope this article will be helpful to you.
One $. fn. live repeat binding
Solution:
Use the die () method to unbind all events bound to the element before binding the live () method, and then bind new events using the live () method.
The Code is as follows: |
Copy code |
// Unbind from the die () method and then use live () Binding $ ("# SelectAll"). die (). live ("click", function (){ // Event Running code }); |
2. Events that unbind live
Solution: Use the unbind ("click") method to unbind the Bound event and then bind the new event. That is, remove the original event on the object before binding the event to the object.
The Code is as follows: |
Copy code |
Var accoutEdit = function (){ $ (This). text ("Unbind event "); // Unbind live $ ('. SetAccoutEdit. option'). die ('click', accoutEdit ); }
// Bind the modification event $ ('. SetAccoutEdit'). live ('click', accoutEdit );
/* Disable the function */ $ ('. EditOption'). live ('click', function (){
$ (This). text ("add binding event "); // Add accoutEdit binding $ ('. SetAccoutEdit. option'). live ('click', accoutEdit );
}); |
In addition
Bind events, unbind events
Events bound with delegate are unbound from undelegate.
Use the on binding event, and use off to unbind