我已经用谷歌搜索过了&我尝试了几个答案,但我的问题仍然存在。我在IIS7上有一个.net网页,代码在IE9中运行良好,但在Firefox中就不行了。我需要它在两个地方都能用。不知道我做错了什么,请帮帮忙。
这是一个简单的页面,只有一个多行文本框,当我点击提交时,一个隐藏的DIV会弹出来,并说,请稍候,正在处理中……不要点击任何东西。(他们可能会提交1000个项目,所以这需要时间。)
奇怪的是,我注意到如果我取消对Alert按钮的注释,警报会弹出,我确实看到了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>发布于 2013-01-25 01:00:00
这可能就是你想要的:
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);
}发布于 2013-01-25 01:01:15
如果您只想显示“正在处理中,请稍候...”然后在4秒后将其清除,这样就可以了
function do_totals1()
{
document.getElementById('pleasewaitScreen').style.display = 'block';
setTimeout(function() {
document.getElementById('pleasewaitScreen').style.display = 'none';
}, 4000);
}发布于 2013-01-25 01:01:44
嗯,基本上你不是这样叫它的,你也可以这样做:
window.setTimeout("do_totals2();",4000);或
window.setTimeout(function(){
do_totals2();
},4000);所以基本上,去掉引号就没问题了
这里有更多信息
http://www.w3schools.com/jsref/met_win_settimeout.asp
https://stackoverflow.com/questions/14506455
复制相似问题