如何使用jquery计算表tbody tr

时间:2017-01-31 07:28:42

标签: javascript jquery

请建议我  我的代码:

$('.Create-New-Order').click(function () {
    var totalRowCount = $("#table_New_Order tbody tr").length;
    alert(totalRowCount);
});

enter image description here

1 个答案:

答案 0 :(得分:1)

加载表tr计数

$(function() {
  $('.Create-New-Order').click(function() {
  var total = $('#mytbl tr').length ;
  alert('tr count = '+ total);
  });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>

<table border="1px solid red">
 <tr>
   <th>Name</th><th>Email</th>
 </tr>
 <tbody id="mytbl">
 <tr>
   <td>sfdsd</td><td>tsdaf@ymail.com</td>
 </tr>
  <tr>
   <td>sfdsd</td><td>tsdaf@ymail.com</td>
 </tr>
  <tr>
   <td>sfdsd</td><td>tsdaf@ymail.com</td>
 </tr>
 </tbody>
</table>
<br>
<br>
<a href="#" class="Create-New-Order">Create-New-Order</a>