• wind.onload和$(document).ready()的区别例示


    例子:

    <html>
    
      <script type="text/javascript" src="jquery-1.7.1.min.js"></script>
      <script type="text/javascript">
        window.onload=function(){
       alert(1);
       var x;
       var imgs=document.getElementsByTagName('img');
       for(var x in imgs)
       imgs[x].width='200';
       alert(2);   
       };   
       
       $(function(){
       alert(1);
       $('img').css('width','200px');
       alert(2);
       });
      </script>
     
    <body>
    <p>123</p>
    <img src='th.jpg' id='myid' />
    <img src='th.jpg' /><img src='th.jpg' /><img src='th.jpg' /><img src='th.jpg' /><img src='th.jpg' />
    </body>
    </html>
     可以看到window.onload结果是先载入所有图片,然后再将图片变化大小。
    而$().ready()则是先改变大小,再载入图片。
  • 相关阅读:
    echarts动态设置主体颜色
    spring security session
    Spark RDD函数:
    MapReduce TOP n
    feign 使用示例
    trie树
    动态修改注解(annotation)值
    golang插件
    Kafka Streams Example
    tcp并发(c18w)
  • 原文地址:https://www.cnblogs.com/Benjamin/p/3392066.html
Copyright © 2020-2023  润新知