setTimeout无法在javascript中运行

时间:2013-11-07 08:29:17

标签: javascript html settimeout

我从插件中获取了以下代码。我用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中的文字会发生变化,但会立即发生变化而不会有任何延迟。有什么帮助吗?

7 个答案:

答案 0 :(得分:2)

setTimeout(function(){$('#result').html(blah)},3000);

答案 1 :(得分:1)

试试这个

setTimeout(function(){
  $('#result').html(blah)
},3000);

答案 2 :(得分:1)

setTimeout(function(){
//your code
}, 3000 );

答案 3 :(得分:1)

函数setTimeout将函数作为第一个参数:

setTimeout(function()
{
  $('#result').html(blah)
}, 3000 );

或者:

function update()
{
  $('#result').html(blah)
}
setTimeout(update, 3000);

答案 4 :(得分:0)

setTimeout(function(){
  $('#result').html(blah)
},3000);

答案 5 :(得分:0)

setTimeout需要将一个函数作为参数传递。

setTimeout(function() {
  $('#result').html(blah)
}, 3000);

答案 6 :(得分:0)

使用:

setTimeout("$('#result').html(blah)",3000);

setTimeout(function(){
  $('#result').html(blah)
},3000);