在一个jsp页面中,每3秒执行一个方法,同时每5秒执行另外一个方法。

如题所述

jsp中定时触发方法是通过js的定时函数来实现的。

js中Document自带的方法: 

定时执行:var tmid = window.setTimeout(“方法名或方法”, “延时”);window.clearTimeout(tmid); 

<script type=”text/javascript”> 

//定时执行,3秒后执行method1() 

window.setTimeout(function(){ 

method1(“method1”); 

},5000); 

//定时执行,5秒后执行method2() 

window.setTimeout(function(){ 

method2(“bbbbbb”); 

},5000); 

</script>

温馨提示:答案为网友推荐,仅供参考
第1个回答  2018-01-05
这个需要后台代码控制,用ajax异步查询比较好,这是我自己写的一段定时执行的js代码,希望能帮到你:
//定时刷新页面
setInterval(function(){
$.get(' <c:url value="/elecform/refresh.shtml"/> ', {}, function (data){
if(data!="nomsg"){
$.messager.anim('show', 1000);
$.messager.show('工单提示:', data);
bgsoundplay("");
}
});
},600000);

window.setInterval(function(){
if(typeof(refreshEnsure)=='function') refreshEnsure();
if(typeof(refreshConstruction)=='function') refreshConstruction();
}, 300000);
相似回答