[英]Jquery: How to get Table cell value in Jquery
<table class="table" align="center" id="tblMain">
<tr>
<td>Status</td>
<td><b><span name="current" value="Dispatch">Dispatch</span></b></td>
</tr>
</table>
JS
$('#tblMain').find('td').ready(function()
if( $('#current').val() == 'Dispatch')
{
alert('Dispatch');
}
else
{
alert('Nothing found');
}
);
我需要表格單元格的值與自己的狀態進行比較,並應按給定的提示進行提醒。如何實現此目標?
<span>
沒有value
屬性,因此它是無效的HTML。 使用自定義data-*
屬性。 current
是元素的name
,而不是id
。 使用attribute selector
通過屬性選擇元素。 ready
應在document
上調用 $(document).ready(function() { if ($('span[name="current"]').data('value') == 'Dispatch') { alert('Dispatch'); } else { alert('Nothing found'); } });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> <span name="current" data-value="Dispatch">Dispatch</span> <!-- ^^^^^^^^^^^^^^^^^^^^^^ -->
$(".table").find("tr td:nth-child(1)").text();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.