当前位置:Gxlcms > JavaScript > JavaScript异步调用定时方法并停止该方法实现代码_javascript技巧

JavaScript异步调用定时方法并停止该方法实现代码_javascript技巧

时间:2021-07-01 10:21:17 帮助过:17人阅读

代码如下:

(function() {
var t = window.setInterval(function() {
$('#ajaxGame').load('RefreshCurrentPlayerServlet #ajaxGame', function() {
youWin();
youlose();
});
}, 10000);

function youWin() {
if ($('#status:contains("YOU ARE THE WINNER!")').length) {
alert("YOU ARE THE WINNER!");
clearInterval(t);
}
}

function youlose() {
if ($('#status:contains("You lost!")').length) {
alert("You lost!");
clearInterval(t);
}
}
});

人气教程排行