簡體   English   中英

jQuery:如何在jQuery中獲取表單元格值

[英]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');
}
);

我需要表格單元格的值與自己的狀態進行比較,並應按給定的提示進行提醒。如何實現此目標?

  1. <span>沒有value屬性,因此它是無效的HTML。 使用自定義data-*屬性。
  2. current是元素的name ,而不是id 使用attribute selector通過屬性選擇元素。
  3. 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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM