How to add a wait timer on an input field keyup event?
问题 I have an input field, and it has a keyup event: $(document).ready(function() { $('#SearchInputBox').keyup(function() { DoSearch($(this).val()); }); }); How can I add a delay time, so that only when the user stopped typing for 1 second, then it will run the DoSearch function. I don't want to keep running it every time the user types a key because if they type fast, then it will lag. 回答1: Basically, set a timeout on each keyup. If there's already a timeout running, clear it and set another.