获取 html 表中选中的复选框
我做了一个表格如下。
在脚本标记中:
<script type="text/javascript">
$(document).ready(function() {
$("#addSelected").live("click", function(e) {
alert("Entered");
$('#LstDocTemp tr').each(function() {
alert($('.chk').is('checked'));
if ($('.chk').is('checked')) {
alert("Clicked");
}
});
});
});
</script>
html 部分:脚本
<div class="grid_top_button">
<div class="left_top_curve">
</div>
<div class="right_top_curve">
</div><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=
'%3C%=%20Url.Action("DetailsDocumentTemplate",%20"Document",%20new%20{%20id%20=%20item.DocId%20})%%3E'>
<%=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>
中的 alert($('.chk').is('checked'));
始终返回 false。我需要通过选中相应的复选框来对所有选择的行执行更新操作。
I have made a table as below.
in script tag:
<script type="text/javascript">
$(document).ready(function() {
$("#addSelected").live("click", function(e) {
alert("Entered");
$('#LstDocTemp tr').each(function() {
alert($('.chk').is('checked'));
if ($('.chk').is('checked')) {
alert("Clicked");
}
});
});
});
</script>
the html part:
<div class="grid_top_button">
<div class="left_top_curve">
</div>
<div class="right_top_curve">
</div><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=
'%3C%=%20Url.Action("DetailsDocumentTemplate",%20"Document",%20new%20{%20id%20=%20item.DocId%20})%%3E'>
<%=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>
alert($('.chk').is('checked'));
in the script is always returning false. I need to do an updation action for all the rows that are selected by checking the corresponding checkbox.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我相信 $('.chk') 将返回网格中的所有复选框。
你想做这样的事情(未经测试!):
})
I believe $('.chk') will return all checkboxes in the grid.
You want to do somehting like this (untested!) :
})