简体   繁体   English

window.onload = function () vs window.onload= 的区别

[英]Difference between window.onload = function () vs window.onload=

Hello I have an aspx document, at the bottom of the page I have this code:您好,我有一个 aspx 文档,在页面底部我有以下代码:

<script language="javascript" type="text/javascript">
      window.onload = migrate();
</script>

It works well, but it does a flickering in the page.它运行良好,但它在页面中闪烁。 The flickering is because I use a translation system... But if I put:闪烁是因为我使用了翻译系统......但如果我把:

   <script language="javascript" type="text/javascript">
     window.onload = function () {
            migrate();
        }
    </script>

The flickering dissapear.闪烁消失。

What is the difference?有什么不同?

Thanks!谢谢!

In the first code snippet, you are calling the migrate() function and assigning it the value returned from window.onload .在第一个代码片段中,您正在调用migrate()函数并为其分配从window.onload返回的值。 (Assuming migrate() returns a function object). (假设migrate()返回一个函数对象)。

In the second code snippet, you are defining the onload function which in turn will call the migrate() method.在第二个代码片段中,您正在定义onload函数,该函数将调用migrate()方法。

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

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