2011-01-23 65 views

回答

1

要隱藏一個內的任何span元素:

$(document).ready(function() { 
    $('.msg, .entry').click(function() { 
     $(this).find('span').hide() 
    }); 
}); 

如果你想針對更多的鏈接,你將需要更新'.msg, .entry'選擇太匹配新的元素。我建議你考慮標記你想這與普通類申請,像這樣的元素所有

<a class="entry statusLink" ..>...</a> 
<a class="msg statusLink" ..>...</a> 
<a class="another statusLink" ..>...</a> 
+0

謝謝,這是非常有益的。 – Lucka 2011-01-23 21:37:02

0

的DOM已經在功能結合到事件之前加載的,你可以做什麼..

$(document).ready(function() { 
    $("a, .number").click(function() { 
     $(this).find(".number").hide(); 
    }); 
}); 

文件準備檢查一個粗略的例子。 $(this)表示作爲參數傳遞的對象,在這種情況下是點擊的對象,無論是.number還是鏈接(a)。 .find(數字)用來檢查鏈接是否被點擊過,它只是隱藏.number,而不是整個鏈接標籤。

0

因爲您想跨度隱藏,您需要找到鏈接內的跨度。就像這樣:

$('.msg, .entry').click(function() 
{ 
    $('.number',this).hide(); 
}); 
0

$(document).ready(function() { 
    $('a.msg, a.entry').click(function() { 
     $(this).find('span').hide(); 
     return false; 
    }); 
}); 

這是好事,始終遵循最佳做法,包括與類(優化)的標籤,並用函數返回false