2010-09-22 55 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);