簡體   English   中英

javascript settimeout div未顯示

[英]javascript settimeout div not showing

我已經用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>

這可能是您要的:

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);
}

如果您只想顯示“請稍候,請稍候...”,然后在4次查看后將其清除,則可以

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

好吧,基本上,您不會那樣稱呼它:

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

要么

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

所以基本上刪除引號就可以了

這是更多信息

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM