foreach 循环中的 JQuery 复选框操作
我做了一个表格如下。
<div class="grid_top_button">
<div class="left_top_curve">
</div>
<div class="right_top_curve">
</div>
<input name="input" type="button" id="addSelected" name="addSelected" class="section_btn"
value="Link" />
</div>
<table id="LstDocTemp" border="0" cellpadding="0" cellspacing="0" class="instruction_grid">
<tr>
<th align="left" class="ins_sl_no">
Sl No.
</th>
<th align="left" class="selct_column">
<input type="checkbox" id="chkSelectAll" name="chkSelectAll" />
</th>
<th align="left" class="doc_title_1">
Document title
</th>
<th align="left" class="description">
Description
</th>
<th align="center" class="revision">
Revision
</th>
<th align="left" class="part_no">
Parts name
</th>
<th align="center" class="issue_no">
Issue
</th>
<th align="center">
Link
</th>
</tr>
<% int slNo = 1; %>
<%foreach (var item in Model)
{ %>
<tr id="<%= Html.Encode(item.DocId) %>">
<td>
<%= slNo %>
</td>
<td>
<input type="checkbox" name="chkItem" class="chk" id="chkbox_<%=Html.Encode(item.DocId) %>" />
</td>
<td>
<%= Html.Hidden("DocTitle", item.DocTitle)%>
<a href='<%= Url.Action("DetailsDocumentTemplate", "Document", new { id = item.DocId })%>'>
<%=Html.Encode(item.DocTitle) %></a>
</td>
<td>
<%= Html.Hidden("DocDesc", item.DocDesc)%>
<%= Html.Encode(item.DocDesc) %>
</td>
<td class="dark_highlight">
<%= Html.Hidden("DocRevision", item.DocRevision)%>
<%= Html.Encode(item.DocRevision) %>
</td>
<td>
<%= Html.Hidden("PartListId", item.PartListId)%>
<%= Html.Hidden("PartNo", item.PartNo)%>
<%= Html.Encode(item.PartNo) %>
</td>
<td class="light_highlight">
<%= Html.Hidden("IssueNo", item.IssueNo)%>
<%=Html.Encode(item.IssueNo) %>
</td>
<td>
<%= Html.Hidden("DocId", item.DocId)%>
<a class="icon_add" title="Add">Add</a>
</td>
</tr>
<%slNo++;
} %>
</table>
我需要实现以下目标:
- 在控制器中对通过选中复选框(name =“chkItem”)选择的行执行操作。
- 当选中复选框 (name="chkSelectAll) 时,选中/取消选中复选框 (name="chkItem")。
- 通过选中 chkSelectAll 复选框选择所有内容后,取消选中任何人都应取消选中 chkSelectAll 复选框。
I have made a table as below.
<div class="grid_top_button">
<div class="left_top_curve">
</div>
<div class="right_top_curve">
</div>
<input name="input" type="button" id="addSelected" name="addSelected" class="section_btn"
value="Link" />
</div>
<table id="LstDocTemp" border="0" cellpadding="0" cellspacing="0" class="instruction_grid">
<tr>
<th align="left" class="ins_sl_no">
Sl No.
</th>
<th align="left" class="selct_column">
<input type="checkbox" id="chkSelectAll" name="chkSelectAll" />
</th>
<th align="left" class="doc_title_1">
Document title
</th>
<th align="left" class="description">
Description
</th>
<th align="center" class="revision">
Revision
</th>
<th align="left" class="part_no">
Parts name
</th>
<th align="center" class="issue_no">
Issue
</th>
<th align="center">
Link
</th>
</tr>
<% int slNo = 1; %>
<%foreach (var item in Model)
{ %>
<tr id="<%= Html.Encode(item.DocId) %>">
<td>
<%= slNo %>
</td>
<td>
<input type="checkbox" name="chkItem" class="chk" id="chkbox_<%=Html.Encode(item.DocId) %>" />
</td>
<td>
<%= Html.Hidden("DocTitle", item.DocTitle)%>
<a href='<%= Url.Action("DetailsDocumentTemplate", "Document", new { id = item.DocId })%>'>
<%=Html.Encode(item.DocTitle) %></a>
</td>
<td>
<%= Html.Hidden("DocDesc", item.DocDesc)%>
<%= Html.Encode(item.DocDesc) %>
</td>
<td class="dark_highlight">
<%= Html.Hidden("DocRevision", item.DocRevision)%>
<%= Html.Encode(item.DocRevision) %>
</td>
<td>
<%= Html.Hidden("PartListId", item.PartListId)%>
<%= Html.Hidden("PartNo", item.PartNo)%>
<%= Html.Encode(item.PartNo) %>
</td>
<td class="light_highlight">
<%= Html.Hidden("IssueNo", item.IssueNo)%>
<%=Html.Encode(item.IssueNo) %>
</td>
<td>
<%= Html.Hidden("DocId", item.DocId)%>
<a class="icon_add" title="Add">Add</a>
</td>
</tr>
<%slNo++;
} %>
</table>
I need to achieve the follwing:
- Perform action in the controller for the rows which are selected by checking the checkbox (name="chkItem").
- Check/uncheck the checkboes (name="chkItem") when the checkbox (name="chkSelectAll) is checked.
- After selecting all by checking the chkSelectAll checkbox, and unchecking anyone should uncheck the chkSelectAll checkbox.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
对于第一点,你可以这样做......
对于第二点 -
对于第三点 -
for first point you can do this...
for second point -
for third point -
设置时选择全部
For setting select all