簡體   English   中英

jQuery 動態表行數

[英]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'>&nbsp;</span><span class='glyphicon glyphicon-trash btnDelete black'>&nbsp;</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.

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