One $. FN. Live repeat binding
Solution: Use the die () method. Before binding the live () method, unbind all events previously bound to this element, and then use live () method to bind a new event.
//Unbind from the die () method and then use live () binding.
$ ("# Selectall"). Die (). Live ("click ",Function(){
//Event runningCode
});
Second click and other events
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.
Complete Test code:
< Div class = " Box " >
< Button ID = " Test " > Repeat the binding trigger button < / Button> (click this button twice or more to trigger repeated binding. Then, click the button below to view the result)
< BR / > <Br / >
< Button ID = " Test1 " > Click to repeat the binding test button < / Button>
< Button ID = " Test2 " > Click to bind a test button < / Button>
< Button ID = " Test3 " > Repeat the test button in live. < / Button>
< Button ID = " Test4 " > Live binds a test button < / Button>
< / Div>
< Script Type = " Text/JavaScript " SRC = " ../Static/jquery-1.6.1.min.js " > < / SCRIPT>
< Script Type = " Text/JavaScript " >
$ ( Function (){
VaR I = 1 , J = 1 , K = 1 , H = 1 , N = 1 ;
VaR Triggerbind = Function (){
$ ( " # Test1 " ). Click ( Function (){
Alert ( " Click Is Not unbound from the rebinding. " + J ++ + " Times " );
});
$ ( " # Test2 " ). Unbind ( ' Click ' ). Click ( Function (){
Alert ( " Click unbind execution " + K ++ + " Times " );
});
$ ( " # Test3 " ). Live ( " Click " , Function (){
Alert ( " Live is not unbound and repeated execution " + H ++ + " Times " );
});
$ ( " # Test4 " ). Die (). Live ( " Click " , Function (){
Alert ( " Executed after live is unbound " + N ++ + " Times " );
});
}
$ ( " # Test " ). Click ( Function (){
Triggerbind ();
Alert ( " Trigger binding click " + I ++ + " Times " );
});
});
< / SCRIPT>
Complete Test code: