jquery sometimes has a problem of repeatedly registering an event, causing the click of an event to be repeated, that is, the number of times the event was triggered,
Then the event will be repeated several times by the execution overlay.
My side of a project, when a page is initialized, a control to register an event, and later found that the page entered several times, because the entry page will perform a registration, the event will be registered several times, is repeated, no coverage.
Internet query, summed up the following several situations:
1, the event registered by the on method , each time the registration will not overwrite the original method. will be saved as a queue
When clicked, the trigger event will be executed in the order of registration.
function Initonevent () { // Register a click event for the ID onwaytoevent button $ ("#onWayToEvent") .on ("Click", function () {alert ( "this is one on event "" #onWayToEvent "). On (" click ", function () {alert ( "This is", "the" on event "" # Onwaytoevent "). On (" click ", function () {alert ( this was three on event "
2, the event is registered multiple times via bind method . The method of multiple registration through the Bind method of jquery is the same, it will not overwrite the original method, but also the method to
The queue is saved in the form of the event, and is executed one after the other by the registration order.
function initbindevent () {/// for the Bindwaytoevent-ID button Register Click event $ ("#bindWayToEvent"). Bind ("click", function() {alert ("This was registry event by Bind. One")}); $ ("#bindWayToEvent"). Bind ("click", function () {alert ("This was registry event by Bind.")}); $ ("#bindWayToEvent"). Bind ("click", function() {alert ("This was registry event by Bind. Three")}); </div>
3, register the event multiple times through the click Method . The method of registering multiple times through the click Method of jquery is the same as the above effect.
function Initclickvent () {$ ("#clickWayToEvent"). Click (function() {alert ("This was registry event by Click. One ");}); $ ("#clickWayToEvent"). Click (function() {alert ("This was registry event by click.");}); $ ("#clickWayToEvent"). Click (function() {alert ("This was registry event by Click. Three" );});}
4, register events multiple times through the live method .
How do you want to overwrite the previous event, leaving only the last registered event method?
1, unique registration of events via the Unbind,bind method
$ ("#oneEvnetByBind"). Unbind ("click"). Bind ("click",function() {alert ("only!!!!!!!" );});
2, the only load of events through the Die Live method
$ ("#oneEvnetByDieLive"). Die (). Live ("Click",function() {alert ("The One of your!!!!!!" );});
jquery events, registration and recurring event handling