简体   繁体   English

Windows Onload导致脚本停止在IE中工作

[英]Windows Onload Causing Script to Stop Working in IE

I am running this script: 我正在运行这个脚本:

<script type="text/javascript">
window.onload=function()
{
document.getElementById("loading").style.display = "none";
}
</script>

When I implemented it it my other script stopped working in IE (FF and others work fine) 当我实现它时,我的其他脚本停止在IE中工作(FF和其他工作正常)

Why and what should I do to fix this? 为什么以及我该怎么做才能解决这个问题? I am using jQuery if there is a better way to do the above script and eliminate the issue. 如果有更好的方法来执行上述脚本并消除问题,我正在使用jQuery。

Because you are using jQuery already, please do it like this: 因为你已经在使用jQuery,请这样做:

    $(document).ready(function() {
      document.getElementById("loading").style.display = "none";
    });

or 要么

    $(document).ready(function() {
      $("loading").style.display = "none";
    });

and be aware adding this at the bottom of your HMTL file. 并注意在HMTL文件的底部添加它。

window load and document ready are 2 different events... You are likely to overwrite your previous onload functionality with your code above. 窗口加载和文档就绪是两个不同的事件...您可能会使用上面的代码覆盖以前的onload功能。

$(window).load=function(){...}

should work fine, or you can add to your existing load with something like 应该可以正常工作,或者你可以添加类似的东西

var oldOnLoad = window.onload; 
window.load= function(){ oldOnLoad; yourNewFunction();}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM