小智收集的神奇宝贝:Q&A:JS中ONLOAD相关?在线等,重金悬赏!

来源:百度文库 编辑:中科新闻网 时间:2024/05/10 11:19:08
■■■■■[loading.js]■■■■■

var t_id = setInterval(animate,20);
var pos=0;
var dir=2;
var len=0;
function animate()
{
var elem = document.getElementById('progress');
if(elem != null) {
if (pos==0) len += dir;
if (len>32 || pos>79) pos += dir;
if (pos>79) len -= dir;
if (pos>79 && len==0) pos=0;
elem.style.left = pos;
elem.style.width = len;
}
}
function remove_loading() {
this.clearInterval(t_id);
var targelem = document.getElementById('loader_container');
targelem.style.display='none';
targelem.style.visibility='hidden';
}

document.writeln("<style>#loader_container {text-align:center;position:absolute;top:40%;width:100%;left: 0;}#loader {font-family:Tahoma, Helvetica, sans;font-size:11.5px;color:#000000;background-color:#FFFFFF;padding:10px 0 16px 0;margin:0 auto;display:block;width:130px;border:1px solid #5a667b;text-align:left;z-index:2;}#progress {height:5px;font-size:1px;width:1px;position:relative;top:1px;left:0px;background-color:#8894a8;}#loader_bg {background-color:#e4e7eb;position:relative;top:8px;left:8px;height:7px;width:113px;font-size:1px;}</style>");

document.writeln("<div id=\"loader_container\"><div id=\"loader\"><div align=\"center\">页面正在加载中 ...</div><div id=\"loader_bg\"><div id=\"progress\"> </div></div></div></div> ");

■■■■■[loading.js]■■■■■

如上代码,我用<script src="loading.js"></script>将他引入一个ASP网页中,并在ASP的<body>中加入onload="remove_loading()"或者onload="remove_loading();"

但是结果发现remove_loading()函数并没有被执行,于是我试验着在loading.js直接加入remove_loading(); 结果证明 remove_loading() 函数没有问题,可以正常执行!

所以我现在就是想换一种方法,让 网页完全加载完毕后 执行这个函数!!!!!!!!!!!!!!!!!!!!!

一个最简单的办法,就是把这个函数写在网页的最后面,这样,加载到这个函数的时候,网页的其它部分就已经加载完了。如:

...
...
<script>

remove_loading();

</script>
</body>
</html>