2
是否可以檢查用戶是否有而不是在文本中鍵入<input/>
標記在兩秒鐘內使用javascript?在輸入標記中沒有任何活動之後2秒之後啓用JavaScript函數
<input type="text" onKeyUp="check_last_active()" />
功能應觸發在<input/>
標籤用戶的最後輸入後只2秒東西(警告),由此重置以往任何定時器功能。
是否可以檢查用戶是否有而不是在文本中鍵入<input/>
標記在兩秒鐘內使用javascript?在輸入標記中沒有任何活動之後2秒之後啓用JavaScript函數
<input type="text" onKeyUp="check_last_active()" />
功能應觸發在<input/>
標籤用戶的最後輸入後只2秒東西(警告),由此重置以往任何定時器功能。
var timer;
function onInput() {
clearTimeout(timer);
timer = setTimeout(functionToRunAfter2Seconds.bind(this), 2000);
}
inputElement.addEventListener('input', onInput, false);
輸入事件是用於輸入元件和textarea元素(你正在使用一個假定的)。
您需要清除超時時間,以便在他們再次開始輸入時重置計時器。如果你想jQuery的方式
....
$('#idOfInputOrTextarea').on('input', onInput);