设置你的间隔功能之外:
function clearDivs(){
$("#RLTRightDiv").innerHTML='';
$("#RLTLeftDiv").innerHTML='';
$.mobile.changePage($("#realTimeScreen"),{transition:'none'});
}
var timer = setInterval(function() {
clearDivs();
}, 15000);
或者,您可以使用setTimeout
函数,如果您只需要在一个条件下运行该函数。
function clearDivs() {
$("#RLTRightDiv").innerHTML='';
$("#RLTLeftDiv").innerHTML='';
$.mobile.changePage($("#realTimeScreen"),{transition:'none'});
//If you require a condition, set it here.
if (isTrue) {
//If the given condition is true clear the divs after 15 seconds.
setTimeout(function() {
clearDivs();
}, 15000);
}
}
//Call the div initially after 15 seconds
setTimeout(function() {
clearDivs();
}, 15000);
基于您的评论,如果你想的div到15秒后,每次之后清除在第一时间,然后1秒,做到以下几点:
function clearDivs() {
$("#RLTRightDiv").innerHTML='';
$("#RLTLeftDiv").innerHTML='';
$.mobile.changePage($("#realTimeScreen"),{transition:'none'});
//Re-Call this function every 1 second.
setTimeout(function() {
clearDivs();
}, 1000);
}
//Clear the divs after 15 seconds.
setTimeout(function() {
clearDivs();
}, 15000);
什么是你想怎么办? 'setPageIntervale();'做什么? –
为什么你需要一种不同的方式? – Reeno
如果只应该调用一次(在清除间隔时出现这种情况),请查看window.setTimeout:https://developer.mozilla.org/de/docs/DOM/window.setTimeout – Reeno