[英]jQuery dynamic table row count
我有如下表
<div class="row">
<input type="button" id="btnAddGatePass" value="Add Gate Pass Requester" />
<div class="table-responsive">
<table id="gatePass" class="table table-striped table-hover" cellspacing="0" width="100%">
<thead>
<tr>
<th>Name</th>
<th>Nationality</th>
<th>Job Title</th>
<th>Passport No.</th>
<th></th>
</tr>
</thead>
<tbody></tbody>
</table>
</div>
</div>
并在添加单击我调用下面的函数
$("#gatePass tbody").append(
"<tr>" +
"<td><input type='text' id='txtName' class='form-control'/></td>" +
"<td><input type='text' id='txtNationality' class='form-control'/></td>" +
"<td><input type='text' id='txtJobTitle' class='form-control'/></td>" +
"<td><input type='text' id='txtPassportNo' class='form-control'/></td>" +
"<td><span class='glyphicon glyphicon-floppy-disk btnSave forestgreen'> </span><span class='glyphicon glyphicon-trash btnDelete black'> </span></td>" +
"</tr>");
$(".btnSave").bind("click", Save);
$(".btnDelete").bind("click", Delete);
并在提交按钮单击我正在计算行但总是给我零可能是什么问题
if ($('#gatePass >tbody >tr').length === 0) {
return false;
}
试试下面的代码:-
var rowCount = $('#gatePass tr').length;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.