我有一个列表视图,在标题中有一个复选框。如果标题复选框已选中/未选中,我想选择行中的所有复选框。如何在客户端实现此目标?这是ListView设计代码。
<asp:ListView ID="lvTypes" runat="server" GroupPlaceholderID="groupPlaceHolder1" ItemPlaceholderID="itemPlaceHolder1">
<LayoutTemplate>
<div id="DataTables_Table_0_wrapper" class="dataTables_wrapper" role="grid">
<table id="DataTables_Table_0" class="table table-striped table-bordered bootstrap-datatable datatable responsive dataTable" aria-describedby="DataTables_Table_0_info">
<thead class="box-header well" style="font-size: 12px !important;">
<tr role="row">
<th class="sorting_asc" role="columnheader" tabindex="0" aria-controls="DataTables_Table_0" style="text-align: center; width: 50px;" aria-sort="ascending" aria-label="SNo: activate to sort column descending">S.No
</th>
<th class="sorting" role="columnheader" tabindex="0" aria-controls="DataTables_Table_0" style="text-align: center; width: 188px;" aria-label="Name: activate to sort column ascending">Name
</th>
<th class="sorting" role="columnheader" tabindex="0" aria-controls="DataTables_Table_0" style="text-align: center; width: 200px;" aria-label="Action: activate to sort column ascending">
<asp:CheckBox ID="CheckBox1" runat="server" AutoPostBack="true" OnCheckedChanged="chkSelectAll_CheckedChanged" Text="Action"/>
</th>
<th class="sorting" role="columnheader" tabindex="0" aria-controls="DataTables_Table_0" style="text-align: center; width: 188px;" aria-label="Employee ID: activate to sort column ascending">Desription
</th>
</tr>
</thead>
<tbody role="alert" aria-live="polite" aria-relevant="all">
<asp:PlaceHolder runat="server" ID="groupPlaceHolder1"></asp:PlaceHolder>
</tbody>
</table>
</div>
</LayoutTemplate>
<GroupTemplate>
<tr>
<asp:PlaceHolder runat="server" ID="itemPlaceHolder1"></asp:PlaceHolder>
</tr>
</GroupTemplate>
<ItemTemplate>
<td style="text-align: center;">
<%# Container.DataItemIndex + 1 %>
</td>
<td style="text-align: center;">
<asp:CheckBox ID="cbDelProjectType" Checked="false" runat="server" />
<a class="iframe2 cboxElement" href='<%# ResolveUrl("./Admin_EditPage.aspx?editTemplateId="+ Eval("id").ToString() ) %>'>
<img src="./images/file_edit.png" alt="Edit Type" width="20px" height="20px" />
</a>
</td>
<td style="text-align: center;">
<%# Eval("title") %>
</td>
<td style="text-align: center;">
<%# Eval("description") %>
</td>
</ItemTemplate>
</asp:ListView>
参考方案
首先,将标题Checkbox更改为此。我们不需要将其回发。
<asp:CheckBox ID="CheckBox1" runat="server" AutoPostBack="false" onchange="CheckAll(this);" Text="Action"/>
完成此操作后,在代码中添加以下javascript。
function CheckAll(checkid) {
var updateButtons = $('#DataTables_Table_0 input[type=checkbox]');
if ($(checkid).children().is(':checked')) {
updateButtons.each(function () {
if ($(this).attr("id") != $(checkid).children().attr("id")) {
$(this).prop("checked", true);
}
});
}
else {
updateButtons.each(function () {
if ($(this).attr("id") != $(checkid).children().attr("id")) {
$(this).prop("checked", false);
}
});
}
}
使用C#执行JavaScript页面 - javascript我正在尝试使用C#抓取一个网站。在此过程中的某个时候,网站返回了我需要执行的JavaScript页面,以便它将生成一些参数,然后使用所生成的参数作为查询变量来发布请求。这是JavaScript文件https://jsfiddle.net/7aw5vr59/浏览器生成的结果文件如下所示:<imimxxxyyy id="ActiveX"…
如何在JavaScript中将多个h1元素替换为h1,h2,h3,h4,h5,h6? - javascript@foreach (var item in Model) { <div class="panel-heading"> <h1> <a href="#">@item.Title</a> </h1> </div> } 结果; (每页发布数:6)<…
在提交时在表单操作中获取变量丢失 - javascript当表单由onchange事件提交时,它不会保留get变量view。任何想法为什么会发生这种情况?提交后,这是它进入的网址,index?month=February&year=2014<form action="index?view=list" class="pure-form pure-fo…
选择后显示输入元素 - javascript我有一个表格,其中取决于用户的选择,输入元素是否可见。实际上,用户正在以另一种形式设置已定义的合作伙伴类型,并且如果选中该元素,则允许在该类型的合作伙伴上可见的元素类型1将显示以下元素:<input type="text" id="partner" name="partner" class=&…
JavaScript将PHP中的字符串和整数传递给函数 - javascript我正在尝试将字符串和整数都传递到同一函数中,但是引号引起了问题。我发现错误出在echo $q->info部分,我必须在此代码上使用双引号。有人可以帮我写这个$q->info,但不能获得真正的价值吗?到目前为止,我的代码是<td><a href="javascript:add(<?php echo $q->i…