我的网页上有三个不同的复选框列表。我想要一个显示“全选”的复选框,当选中该复选框时,将选中所有三个复选框列表复选框。我正在看这个例子,通过单击选择按钮来检查一个复选框列表,但我希望在javascript中检查所有三个复选框列表复选框。以下是我的代码
<asp:CheckBox ID="chkCheckAll" runat="server" Text="Check/Uncheck All"
Style="font-weight: 700" CausesValidation="false" oncheckedchanged="chkCheckAll_CheckedChanged" AutoPostBack="true"
/>
<asp:CheckBoxList ID="chkList_MetricsSeverity" runat="server" RepeatDirection="Horizontal"
RepeatColumns="3" Width="1060px">
</asp:CheckBoxList>
<asp:CheckBoxList ID="chkList_MetricsAvgMedian" runat="server" RepeatDirection="Horizontal"
RepeatColumns="3" Width="1060px">
</asp:CheckBoxList>
<asp:CheckBoxList ID="chkList_Counts" runat="server" RepeatDirection="Horizontal"
RepeatColumns="3" Width="1060px">
</asp:CheckBoxList>
任何帮助将不胜感激
答案 0 :(得分:2)
看看here ...你可以找到以asp.net和javascript方式实现上述内容的方法......
答案 1 :(得分:0)
这是需要做的。下面是代码
function CheckAll() {
var chkbx = document.getElementById('<%=chkCheckAll.ClientID %>');
var chkbxList1 = document.getElementById('<%=chkList_MetricsSeverity.ClientID %>');
var chkbxList2 = document.getElementById('<%=chkList_MetricsAvgMedian.ClientID %>');
var chkbxList3 = document.getElementById('<%=chkList_Counts.ClientID %>');
if (chkbx.checked == true) {
var chkbxListCount = chkbxList1.getElementsByTagName('input');
for (var i = 0; i < chkbxListCount.length; i++) {
chkbxListCount[i].checked = true;
}
var chkbxListCount = chkbxList2.getElementsByTagName('input');
for (var i = 0; i < chkbxListCount.length; i++) {
chkbxListCount[i].checked = true;
}
var chkbxListCount = chkbxList3.getElementsByTagName('input');
for (var i = 0; i < chkbxListCount.length; i++) {
chkbxListCount[i].checked = true;
}
}
else {
var chkbxListCount = chkbxList1.getElementsByTagName('input');
for (var i = 0; i < chkbxListCount.length; i++) {
chkbxListCount[i].checked = false;
}
var chkbxListCount = chkbxList2.getElementsByTagName('input');
for (var i = 0; i < chkbxListCount.length; i++) {
chkbxListCount[i].checked = false;
}
var chkbxListCount = chkbxList3.getElementsByTagName('input');
for (var i = 0; i < chkbxListCount.length; i++) {
chkbxListCount[i].checked = false;
}
}
}