我有以下HTML(多次重複),並希望在我點擊的href之前立即獲取span的內容。從點擊中遍歷HTML代碼片段以獲取範圍的內容
<p class="listitem">
<img src="./1.jpg" alt="" width="50" height="50"/>
<span class="votecount">22</span> Votes
<span class="name">Richard Wilde</span>
<a href="ViewEntry.aspx?Id=1019">View Entry</a>
<div id="id-1"><a href="#" rel="vote-1019" >...</a></div>
</p>
我也有以下的jquery,我想用22填充計數,但似乎無法找出這一個。
$("a[rel^='vote']").click(function() {
var id = ($(this).attr("rel")).replace("vote-", "");
$(this).unbind("click");
var count= $(this).parent("div").parent(".listitem").children(".votecount");
return false;
});
編輯對不起,連我在最後我得到空加的.text(),我覺得遍歷並不完全正確。
請參閱我編輯的答案。複製你的代碼,並得到它的工作,但解決方案沒有多大意義.... –