可以用在AJAX程序中,当用户停止输入5秒后,进行数据提交,为AJAX的节流模式
<
html
>
< head >
< script language = " JavaScript " type = " text/javascript " >
var time = null ;
function send() ... {
if(time!=null)...{
clearTimeout(time);
time=null;
}
time=setTimeout(function()...{alert("send complete")},5000);
}
</ script >
</ head >
< body >
< input type = " text " onKeyPress = " send() " />
</ body >
</ html >
< head >
< script language = " JavaScript " type = " text/javascript " >
var time = null ;
function send() ... {
if(time!=null)...{
clearTimeout(time);
time=null;
}
time=setTimeout(function()...{alert("send complete")},5000);
}
</ script >
</ head >
< body >
< input type = " text " onKeyPress = " send() " />
</ body >
</ html >