2010-09-22 47 views
1

我有以下定时定期更新我的网页:嵌套每个标准

var refreshId = setInterval(function() { 
    $(".content").each(function(i) { 
     // Do stuff 
     $(this).each(function(i) { 
      // issue here 
     }); 
    }); 
}, 10000); 

内嵌套的foreach循环,我想只提取图像,所以基本上,我会想匹配这个> .icons > .img,因为我的图像位于类“图标”类的div内。

的部分的标记将类似于以下内容:

 <div class="content"> 
      <div></div> 
      <div class="icons"> 
       <img id="dynamicImage12345" src="#"> 
      </div> 
     </div> 

我怎样才能做到这一点?

回答

1

您需要这条线有:

$("div.icons > .img", $(this)).each(function() { 
    // your code to for images 
}); 

假设你正在使用img类的图像作为可以从代码可以看出。如果你不使用类,可以改为尝试这个办法:

$("div.icons > img", $(this)).each(function() { 
    // your code to for images 
}); 

所以就变成:

var refreshId = setInterval(function() { 
    $(".content").each(function(i) { 
    // Do stuff 
    $("div.icons > img", $(this)).each(function() { 
     // your code to for images 
    }); 
    }); 
}, 10000); 
+0

我添加了一个更清晰图片的样本标记。还是一样的答案? – 2010-09-22 19:00:18

0

如果我读这个权利,你要的是这样的:

var refreshId = setInterval(function() { 
    $(".content").each(function(i) { 
     // Do stuff 
     $(".icons > .img", this).each(function(i) { 
      // issue here 
     }); 
    }); 
}, 10000);