Preventing a callback from executing until input stops
问题 A timer to fire an AJAX call if no key is pressed. If a key is pressed, then abort the last timer and add a new timer. That is what I want to do but failed to success. Here is my code: var t; input.onkeyup = function(){ $('.confirmText').html('Checking...'); var timeStampObj = new Date() var timeStamp = timeStampObj.getTime(); var oldTimeStamp = $(this).attr('timeStamp');//I store a timeStamp in the element if(timeStamp < 500 + oldTimeStamp){ $(this).attr('timeStamp', timeStamp); clearTimeout