单击复选框时获得复选框列表的选中/未选中状态 [英] get the checked/unchecked state of checkboxlist when clicking a checkbox
问题描述
海,
我有一个ASP复选框列表,其中包含从数据库绑定的项目.它具有以下方式的项目.
PO_1
PO_2
DNPR_1
DNPR_2
DNPR_3
选中任何带有"DNPR"的复选框时,所有其他复选框都应取消选中并禁用.
我必须使用javascript来实现.
为此,我想在单击复选框列表中的复选框时获取选中/未选中状态以及选中/未选中复选框的ID.
我尝试使用onclick javascript事件来实现此目的.但是即使我选中了一个复选框,onclick事件中的checked = false也是如此.
在哪个javascript事件中,我得到了选中/未选中复选框的状态.
请帮忙.
问候,
Regeesh Joseph
Hai,
I have an asp checkboxlist with items bound from database. It has items in the following manner.
PO_1
PO_2
DNPR_1
DNPR_2
DNPR_3
When any checkbox with ''DNPR'' is checked, all other checkboxes should be unchecked and disabled.
I have to implement it using javascript.
For that, I want to get the checked/unchecked state and the id of the checked/unchecked checkbox when clicking a checkbox in checkboxlist.
I tried using the onclick javascript event to achieve this. But checked=false in the onclick event evenif I checked a checkbox.
In which javascript event, I get the state of the checkbox I checked/unchecked.
Please help.
regards,
Regeesh Joseph
推荐答案
在单击事件中将起作用....
in click event it will work....
function myfn() {
var dlist = document.getElementById("CheckBoxList1");
var count = dlist.cells.length;
for (var i = 0; i < count; i++) {
var cId = "CheckBoxList1_" + i;
//cId is the dynamic id created for checkboxes in the list
var cbox = document.getElementById(cId);
if (cbox.checked == true) {
alert("ok");
}
}
}
<asp:CheckBoxList ID="CheckBoxList1" runat="server"
onclick="myfn()">
<asp:ListItem>one</asp:ListItem>
<asp:ListItem>two</asp:ListItem>
<asp:ListItem>three</asp:ListItem>
<asp:ListItem>four</asp:ListItem>
</asp:CheckBoxList>
这对我有用.
this is working for me..
这篇关于单击复选框时获得复选框列表的选中/未选中状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!