ユーザーがJqueryの入力を停止した5秒後に呼び出すことができる関数はありますか?
ありがとう
function afterTypeProcess(){
//Dosomething
}
var timeid;
$("input").keyup(function(){
clearTimeout(timeid);
timeid = setTimeout(afterTypeProcess, 5000);
});
keyup
各イベントのタイムアウトをクリアしてリセットするだけです。
var countdown;
$("textarea:first").on("keyup", function(){
clearTimeout(countdown);
countdown = setTimeout(function(){
console.log("Fired");
}, 5000);
});
ここでこのjsfiddleを確認してください
$(document).on("change", ".test", function(){
window.setTimeout(dothis, 5000);
});
function dothis(){
alert('test');
}
keyupとsetTimeoutでうまくいくはずです。ここでjsfiddleを確認でき ますテキスト入力の場合
次のコードを使用してキーアップを確認できます
$("#entersomething").keyup(function(e) {
setTimeout(function(){ alert("up"); }, 5000);
});