預先載入1,載入1

來源:互聯網
上載者:User

預先載入1,載入1
<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
</head>
<body>
<ul id="imgList">
</ul>
<script type="text/javascript">
    var imgs=["http://www.wallcoo.com/nature/da_ps_landscape_01/wallpapers/1680x1050/%5Bwallcoo_com%5D_April_23rd.jpg",
        "http://pic5.bbzhi.com/chuangyibizhi/zuixinchuangyishejibizhi/zuixinchuangyishejibizhi_415791_11.jpg",
        "http://img.bz1111.com/d3/2010-10/2010103021073576056.jpg",
        "http://www.pp3.cn/uploads/20120627gj/bz_gj_05.jpg",
        "http://www.onegreen.net/Article/UploadFiles/200811/2008111874946653.jpg",
        "http://lib.nit.net.cn/dlib/resource/jpg/1889.jpg",
        "http://www.lwdx.cn/UploadFiles/Photo/2009/2/bizhi/stzw20081005/stzw20081005_001.jpg"
    ];


    var ul1= document.getElementById('imgList');
    var iNow=0;
    for(var i=0;i<imgs.length;i++)
    {
        (function(n){  //必須在閉包裡面運行
           var yImg=new Image(); //每次迴圈建立一個臨時Image對象
           yImg.src=imgs[n];
            yImg.onload=function()
            {
                var dd=document.createElement("li"); //每次建立一個臨時變數
                dd.innerHTML="<img src='"+yImg.src+"'/>";
                ul1.appendChild(dd);
                iNow++;
               // console.log(iNow);
            };
        })(i);//把迴圈的i傳遞進去
    }


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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.