我有以下从插件中取出的代码。我对 JavaScript 的经验和知识非常少。我试图延迟 html 中文本的更改。这是我的代码:
function printResult() {
var res;
var blah="OKAY B****!";
if(win[a.pos] === win[b.pos] && win[a.pos] === win[c.pos]) {
res = "You Win!";
} else {
res = "You Lose";
}
$('#result').html(res);
if(res=='You Lose'){
setTimeout($('#result').html(blah),3000);
}else{}
}
#result
中的文本发生变化,但它立即变化,没有延迟。
最佳答案
setTimeout(function(){$('#result').html(blah)},3000);
关于javascript - setTimeout 在 JavaScript 中未按预期工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19831077/