在jquery中循环.load

时间:2012-03-30 09:53:29

标签: jquery

为什么load()函数循环几乎23次,当时我只有8个带.image类的元素

$(document).ready(function()
{
    var i=0;

    $('.image').load(function(){
    console.log(i++);
    });
});

我的HTML是

<div class="pel homepics">
    <div class="left i1" ><a href="#" ><img class="image" src="image1.png"/></a></div>
    <div class="left i1" ><a href="#" ><img class="image" src="image1.png"/></a></div>
    <div class="left i1" ><a href="#" ><img class="image" src="image1.png"/></a></div>
    <div class="left i1" ><a href="#" ><img class="image" src="image1.png"/></a></div>
    <div class="left i1" ><a href="#" ><img class="image" src="image1.png"/></a></div>
    <div class="left i1" ><a href="#" ><img class="image" src="image1.png"/></a></div>
    <div class="left i1" ><a href="#" ><img class="image" src="image1.png"/></a></div>
    <div class="left i1" ><a href="#" ><img class="image" src="image1.png"/></a></div>
</div>

1 个答案:

答案 0 :(得分:0)

$(document).ready(function()
{
    $.each($('.image'),function(i,ele){
        $(ele).load(function(){
            alert(ele.attr("title")+" loaded");
        });    
    });    
});