JavaScript等待一定时间后执行方法


<input id="otxt" type="text" />
<script>
function onSub(){
 alert('验证');
}
var timer =null
document.getElementById('otxt').onkeyup =function(){
 clearTimeout(timer);
 timer = setTimeout(onSub, 2000);
}
</script>

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注