我想檢查一個元素是否在其中沒有hrefs(即它是空的),如果是,就隱藏與它關聯的標籤。頁面上會有幾個元素需要檢查,如果它們是空的,所以我需要編寫一個循環。我需要幫忙寫循環。這裏是我的代碼到目前爲止:用JQUERY寫一個循環
if(jQuery('span.tags').is(':empty')) {
jQuery('span.label').hide()
};
請有人可以幫我這個代碼?
這是我的HTML
<div class="entry-meta">
<span class="label">Tagged:</span>
<span class="tags">
<a href="#" rel="tag">Career change</a>,
<a href="#" rel="tag">career change e course</a>,
<a href="#" rel="tag">career help</a>
</span>
</div><!-- END .entry-meta -->
謝謝大家誰回答了這個帖子。這是有效的解決方案。
//Removes word 'Tagged:' if there are no tags
jQuery('span.tags:empty').prev('span.label').hide();
你能告訴我們你會使用這個代碼一些HTML。 – 2011-06-16 09:45:57
[如何在jQuery中執行「For」循環?](http://stackoverflow.com/questions/5287669/how-to-perform-a-for-loop-in-jquery) – 2011-06-16 09:46:26
for the loop ,請檢查jQuery中的.each方法 – Locksfree 2011-06-16 09:48:10