• JavaScript中window.onload和document.onload有什么区别?


    JavaScript中window.onload和document.onload有什么区别?

    document.onload

    在加载图像和其他外部内容之前将其触发。文件。在window.onload之前触发onload事件。

    window.onload

    加载整个页面(包括图像,脚本,css等)时,它将被触发。

    示例

    这是一个了解onload的示例。

    <html>
       <head>
          <title>JavaScript Animation</title>
          <script>
             <!--
                var imgObj = null;
             
                function init() {
                   imgObj = document.getElementById('myImage');
                   imgObj.style.position= 'relative';
                   imgObj.style.left = '0px';
                }
    
                function moveRight() {
                   imgObj.style.left = parseInt(imgObj.style.left) + 10 + 'px';
                }
                window.onload =init;
             //-->
          </script>
       </head>
    
       <body>
          <form>
             <img id="myImage" src="/images/html.gif" />
             <p>Click button below to move the image to right</p>
             <input type="button" value="Click Me" onclick="moveRight();" />
          </form>
       </body>
    </html>
     
     
  • 相关阅读:
    Python基础之内存管理与垃圾回收机制
    Git常用命令
    Git分支操作
    码云配置SSH公钥
    Git基本操作
    Git基本理论
    版本控制
    Python基础之Python语法
    成为一名JAVA高级工程师你需要学什么【转】
    一个java高级工程师的进阶之路【转】
  • 原文地址:https://www.cnblogs.com/sexintercourse/p/16839509.html
Copyright © 2020-2023  润新知