javascript settimeout div没有显示

时间:2013-01-24 16:47:00

标签: javascript settimeout

我用google搜索&我尝试了几个答案,但我的问题仍然存在。我在IIS 7上有一个.net网页,代码在IE9中运行良好,但在Firefox中运行不正常。我需要它在两者中工作。不确定我做错了什么,请帮忙。

这是一个带有一个多行文本框的简单页面,当我点击提交隐藏的DIV时,应该弹出并说,请等待这个处理...不要点击任何东西。(他们可能会提交1000个项目所以需要时间。)

奇怪的是,我注意到如果我取消注释警报按钮,警报弹出,我实际上看到DIV,但如果我拿走警报按钮,我没有看到它。

这是我的javascript。

function do_totals1()
    {
        // alert("Here-1");
        document.getElementById('pleasewaitScreen').style.display = 'block';

        // alert("Here-2!");
        do_totals2();

         window.setTimeout(function () {
         "do_totals2()";
         }, 4000);
        //            
        // alert("Here-3!");
        // window.setTimeout("do_totals2()", 1);
     }

function do_totals2()
    {
         alert("Here-4!");
         wait(4000);
         document.getElementById('pleasewaitScreen').style.display = 'none';
    }



<div id="pleasewaitScreen" style="display:none;position:absolute;z-index:5;top:50%;left:5%;">
 <table bgcolor="#000000" border="1" style="border-color:blue; height:300;width:400" cellpadding="0" cellspacing="0">
    <tr>
        <td style="width:100%;height:100%" bgcolor="#CCCCCC" align="center" valign="middle">
        <br /><br />  
        <font face="Helvetica,Verdana,Arial" size="5" color="#000066"><b>Processing... Don't click on anything until ESN(s) populate the grid below.</b></font>
            <br /><br />
        </td>
    </tr>
 </table>
</div>

3 个答案:

答案 0 :(得分:1)

这可能是你要求的:

function do_totals1() {
    document.getElementById('pleasewaitScreen').style.display = 'block';
    // we don't want to call do_totals2 directly, because it is what hides the element.
    window.setTimeout(do_totals2, 4000);  // setTimeout accepts a function reference
}

function do_totals2() {
    // if wait is effectively a thread sleep function, you don't want to use it.
    // if javascript doesn't release control of the thread (there's only one for your browser tab), 
    //the UI will never be updated, and you won't see that the element was shown.
    document.getElementById('pleasewaitScreen').style.display = 'none';
}

如果你所做的只是显示一个元素然后在4秒后隐藏它,你可以改为:

function do_totalsN(){
    var ele = document.getElementById('pleasewaitScreen');
    ele.style.display = 'block';
    setTimeout(function(){
        ele.style.display = 'none';
    }, 4000);
}

答案 1 :(得分:0)

如果您只想显示“请等待此处理...”,然后在4秒后清除它,这将会执行

function do_totals1()
{
    document.getElementById('pleasewaitScreen').style.display = 'block';
    setTimeout(function() {
        document.getElementById('pleasewaitScreen').style.display = 'none';
    }, 4000);
}

答案 2 :(得分:-1)

好吧,基本上你没有这样称呼你这样做:

window.setTimeout("do_totals2();",4000);

window.setTimeout(function(){
    do_totals2();
},4000);

所以基本上,删除引号,你会没事的

以下是更多信息

http://www.w3schools.com/jsref/met_win_settimeout.asp