日期:2014-05-16  浏览次数:20385 次

js函数执行问题
执行一个比较耗时的函数,想在函数执行的时候用div显示一个提示信息,但是实际运行的时候div却无法显示出来,如果函数执行前alert一个对话框是可以看到div的,该怎么办啊??
代码下:

function   DownExcelTemplate()
{
WaitDiv.Msg   =   "正在生成Excel模版,请稍候... ";
WaitDiv.ShowMsg();

//一些验证代码

if(pa.length   ==   0)
{
alert( "请先选择项目然后下载模版! "); //如果执行到这里可以看到div
WaitDiv.HiddenMsg();
return   false;
}

CreateExcelTemplate(pa); //生成Excel,比较耗cpu,执行时我的机器大约占到60%

WaitDiv.HiddenMsg();
return   false;
}

------解决方案--------------------
我是这么用的
html部分:
<div id= 'div1 ' style= 'visibility:hidden '>
<label> 正在上传,请稍后... </label>
</div>

在做复杂处理的时候,调用 js

div1.style.visibility=\ "visible\ "; //div显示
...(做复杂处理)

用着还可以了,你试试吧
------解决方案--------------------
<html>

<head>
<meta http-equiv= "Content-Type " content= "text/html; charset=gb2312 ">
<title> 信息提示 </title>
</head>
<script language= "javascript ">
function show()
{
document.getElementById( "loading ").style.display= " ";
document.getElementById( "backloading ").style.display= " ";
}
function clos()
{
document.getElementById( "loading ").style.display= "none ";
document.getElementById( "backloading ").style.display= "none ";
}
</script>
<body style= "margin:0px;padding:0px;font-size:12px;overflow-y:hidden;z-index:0; " >
<div id= "loading " style= "background:#FFFFFF;color:#FFF;width:482px;height:110px;padding-left:5px;position: absolute;line-height:22px;z-index:30;display:none;margin-top:expression(body.clientHeight/2-110/2);margin-left:expression(body.clientWidth/2-482/2); ">
<table border= "1 " width= "482 " cellspacing= "1 " style= "border-collapse: collapse " bordercolor= "#D8DDFE " align= "center ">
<tr>
<td bgcolor= "#D8DDFE "> 信息提示 </td>
</tr>
<tr>
<td height= "54 "> <span class= "swTit "> 测试按钮 </span> </td>
</tr>
<tr>
<td align= "center " bgcolor= "#C0C0C0 "> <span onclick= "clos() "> 关闭 </span> </td>
</tr>
</table>
</div>
<div id= "backloading " style= "width:100%;height:100%;position:absolute;z-index:20;border:0px;background-color:#cccccc;filter:alpha(opacity=50);display:none; "align= "center "> </div>

<form method= "POST " action= "--WEBBOT-SELF-- ">
<p>   </p>
<p>   </p>
<p> <input type= "button " value= "按钮 " name= "B3 " onclick= "show() "> </p>
<p>   </p>
</form>

</body>

</html>
------解决方案--------------------
可以用setTimeOut()延缓执行CreateExcelTemplate(pa)的时间