[英]Return value of next span
我正在嘗試使用某個 class ID 返回下一個/壁櫥跨度的值。 我非常接近,但我很困惑如何使用next()
和closest()
任何幫助都會很棒
HTML:
<table width="80%" cellspacing="0" cellpadding="0" >
<th scope="col">Data</th>
<tr>
<td width="20%"><a href="#" class ="show_data_link">Show Data</a>
<span class="data">1 </span>
</td>
</tr>
<tr>
<td width="20%"><a href="#" class ="show_data_link">Show Data</a>
<span class="data">2 </span>
</td>
</tr>
<tr>
<td width="20%"><a href="#" class ="show_data_link">Show Data</a>
<span class="data">3 </span>
</td>
</tr>
</table>
JAVASCRIPT
$('.show_data_link').bind('click', function(){
//returns the first class
alert($('.data').html());
//returns null
//alert($('.data').next().html());
//returns null
// alert($('.data').closest().html());
return false;
});
如果我使用$('.data').html()
我可以獲得第一個跨度的值,只是不確定如何獲得壁櫥跨度的值,所以鏈接點擊了 JSFiddle
你可以使用alert($(this).next().html());
像這樣
當您使用$('.data')
時,它會獲取所有帶有class="data"
的元素,無論您點擊了哪個女巫
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.