因此,我猜想完成键入意味着您只需停顿一会儿,例如5秒钟。因此,请记住,让我们在用户释放按键时启动计时器,并在用户按下按键时将其清除。我决定有问题的输入将是#myInput。
做一些假设…
//setup before functionsvar typingTimer; //timer identifiervar doneTypingInterval = 5000; //time in ms, 5 second for examplevar $input = $('#myInput');//on keyup, start the countdown$input.on('keyup', function () { clearTimeout(typingTimer); typingTimer = setTimeout(doneTyping, doneTypingInterval);});//on keydown, clear the countdown $input.on('keydown', function () { clearTimeout(typingTimer);});//user is "finished typing," do somethingfunction doneTyping () { //do something}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)