我有一个动态创建的文本框集合(通过按钮单击),并且所有文本框都是必需的。一旦文本框为空,则应将错误消息添加到当前验证摘要中。有关如何执行此操作的任何帮助。
Javascript代码
var rowsid = 0;
// Add button functionality
$("#btnAddButton").live("click", function () {
rowsid++;
var master = $(this).parents().find("table.dynamictable"); //$(this).parents("table.dynatable");
// Get a new row based on the prototype row
var prot = master.find(".prototype").clone();
prot.attr("class", "");
prot.find(".id").attr("value", "00000" + rowsid);
master.find("tbody").append(prot);
});
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" data-val-required="This field is required" /></td>
<td><input type="text" name="packagecost[]" value="0" class="pkcost" style="text-align: right" /></td>
<td><input type="text" name="noofattendees[]" value="0" class="nfattendees" style="text-align: right"/></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"/></div>
</div>