单击保存按钮时,我需要验证生成的 html 表(网格)中的文本框值。以下是我到目前为止所拥有的。我使用 Firebug 跟踪代码,它只循环第一行,但我需要循环从标签内第二行开始的行。请提供任何帮助。
html代码
<div class="msg-body">
<table class="dynamictable">
<thead>
<tr>
<th style="display: none"></th>
<th>Package Name</th>
<th>Package Cost</th>
<th>No. of Attendees</th>
<th>Delete</th>
</tr>
</thead>
<tbody>
<tr class="prototype">
<td style="display: none"><input type="hidden" name="id[]" value="" class="id" /></td>
<td><input type="text" name="packagename[]" value="" class="pkname" /></td>
<td><input type="text" name="packagecost[]" value="" class="pkcost"/></td>
<td><input type="text" name="noofattendees[]" value="" class="nfattendees"/></td>
<td>@Html.ActionImage("", null, "~/Content/Images/delete.gif", "Delete", new { @class = "deleterows" }) </td>
</tr>
<tr>
<td style="display: none"><input type="hidden" name="id[]" value="" class="id" /></td>
<td><input type="text" name="packagename[]" value="" class="pkname" /></td>
<td><input type="text" name="packagecost[]" value="" class="pkcost"/></td>
<td><input type="text" name="noofattendees[]" value="" class="nfattendees"/></td>
<td>@Html.ActionImage("", null, "~/Content/Images/delete.gif", "Delete", new { @class = "deleterows" }) </td>
</tr>
</tbody>
</table>
<div style="padding:20px 0 20px 100px "><input type="button" id="btnAddButton" value="Add New" class="button addbutton"/><input type="button" id="btnSaveRow" value="Save" class="button addbutton"/></div>
</div>
Javascript代码
$("#btnSaveRow").click(function () {
$('.dynamictable tr').each(function () {
var $val = $("input[type='input']").val();
if ($val == "") {
alert("Please enter data");
$(this).focus();
return false;
}
return true;
});