使用setTimeout函数

时间:2013-08-08 00:01:24

标签: javascript

我正在尝试设置我的onblur所以它显示加载条3秒......但是代码似乎只是错过了它并直接进入第二个函数...

function seriesIdOnBlur()
{       
    document.getElementById("series_id_check").innerHTML = "<img src='http://www.webscriptlab.com/file/loading/output/13759195689.gif' /> ";

    setTimeout(seriesIdOnBlur2(), 3000);
}

function seriesIdOnBlur2()
{
    var id = document.getElementById("series_id").value;

    var message = "";

    if (series[id] === undefined)
    {
        message = "The Series ID you input was invalid";
    }
    else
    {
        var seriesId = series[id];

        var game = seriesId['game'];
        var name = seriesId['name'];
        message = "ID: " + id + " is for the " + name + " series playing " + game + ".";

    }

    document.getElementById("series_id_check").innerHTML = "<span>" + message + "</span>";
}
对于ID为seriesIdOnBlur的输入,

onBlur被称为series_id

我对setTimeout做错了什么?

1 个答案:

答案 0 :(得分:8)

您正在调用该函数并将结果传递给setTimeout。您希望将该函数传递给setTimeout

setTimeout(seriesIdOnBlur2, 3000);