Some front-end logics sometimes control front-end display, such as recording the number of favorites. Sometimes repeated clicks may cause a front-end display bug. Therefore, some logic judgment is required to remove repeated clicks.
The implementation part of the code is as follows, mainly through setTimeout to determine, that is, no matter the number of clicks, a certain period of time will trigger an event, so that only one record is generated:
<SCRIPT> var I = 0; // determine the number of clicks stored var closetimer = NULL; // delay function storage function button#click () // botton Click Event {console. log ('1'); I ++; // record the number of clicks closetimer = Window. setTimeout (setout, 200);} function setout () {// click the execution event if (I> 1) // if the number of clicks exceeds 1 {console. log ('wrong '); window. cleartimeout (closetimer); // clear the delay function closetimer = NULL; // set the delay storage to null // Add the operation code I = 0; // reset the number of clicks to 0} else {// if the number of clicks is 1 Console. log ('right'); I = 0; // reset the number of clicks to 0 // Add the code to execute the operation }}</SCRIPT>