中setInterval与setTimeout用法
JS里设定延时:
使用setInterval和设定延时函数setTimeout 很类似。setTimeout 运用在延迟一段时间,再进行某项操作。
setTimeout("function",time) 设置一个超时对象
setInterval("function",time) 设置一个超时对象
setInterval为自动重复,setTimeout不会重复。
clearTimeout(对象) 清除已设置的setTimeout对象
clearInterval(对象) 清除已设置的setInterval对象
<script type="text/javascript" src="<%=request.getContextPath()%>/webcontext/js/prototype-1.4.0.js"></script>
function refresh() {
var url = "<%=strPath%>/webcontext/pages/login/freshTZTG.jsp?"+Math.random();
new Ajax.Updater("tztgw", url, {method: "get"});
}
setInterval("refresh();",1000*5);
function refresh() {
var url = "<%=strPath%>/webcontext/pages/login/freshTZTG.jsp?"+Math.random();
new Ajax.Updater("tztgw", url, {method: "get"});
setTimeout("refresh();",1000*5);
}
refresh();