Javascript: How to Use Date.Now() to implement front-end frequency limit

For example, a click event can only be clicked once in two seconds.

    var ms = 1000 * 2 ;
     var lastClick = Date.now()- ms;
    $( " a,div,p,li " ).click(function(){
         if (Date.now()-lastClick >= ms) {
            lastClick = Date.now();
             // Related operation
        
        }
    });    

Date.Now() is the millisecond value of the returned timestamp

Read More:

Leave a Reply

Your email address will not be published. Required fields are marked *