jquery click event in cumulative trigger problems

When using the continuous trigger onclick event, assuming that the trigger 10 times function, we just click once below the click event bindings, it will repeat the 10 times.

The jquery click event onclick, effect on every point of the implementation of a superposition. Note that superposition does not clear before. Repeated clicks will lead to a triggering multiple requests to the background.

solve:

$ ( '# boxID'). One ( 'the Click', function () { // Click event is triggered only once 
 
    // the code to be executed 
})

 

One () method is to add one or more elements selected from the event handler, and when the predetermined function to run when the event occurs.

When using one () method, each element can only run one event handler function.

$(selector).one(event,data,function)

event: Required. Provisions added to an element or multiple events. Separate multiple values ​​by a space events. It must be a valid event.

data: Optional. Provision of additional data passed to the function.

function: Required. When the prescribed function to run when the event occurs.

Guess you like

Origin www.cnblogs.com/hpwd/p/12456271.html