我有一个aspx页面,其中有三个占位符。现在我在每个占位符中都有复选框。如何在clientside中检索复选框的checked属性。我尝试了以下代码,但它不起作用。
<asp:CheckBox ID="lblIsActive" runat="server" CssClass="s_label" />
function Mark_Confirm(elem)
{
//var chk=document.getElementById("<%=lblIsActive.ClientID%>");
var div = document.getElementById('<% = lblIsActive.ClientID %>');
var chk = div.getElementsByTagName('input');
var len = chk.length;
if (chk.type == 'checkbox')
chk.checked = elem.checked;
if(chk.checked==true)
{
if (confirm("Do you want to mark the device as lost?"))
{
var confirm_value1 = document.createElement("INPUT");
confirm_value1.type = "hidden";
confirm_value1.name = "confirm_value1";
confirm_value1.value = "Yes";
}
else
{
confirm_value1.value = "No";
}
}
if(chk.checked==false)
{
if (confirm("Do you want to mark the device as active?"))
{
var confirm_value2 = document.createElement("INPUT");
confirm_value2.type = "hidden";
confirm_value2.name = "confirm_value2";
confirm_value2.value = "Yes";
}
else
{
confirm_value2.value = "No";
}
}
document.forms[0].appendChild(confirm_value1);
document.forms[0].appendChild(confirm_value2);
}
答案 0 :(得分:2)
你可能正在寻找这个。使用“checked
”属性
var isChecked = document.getElementById('<%=lblIsActive.ClientID%>').checked;
alert(isChecked);
或者通过使用jquery,您可以像这样检查属性
var isChecked = $("#<%=lblIsActive.ClientID%>").is(':checked');
alert(isChecked);
答案 1 :(得分:0)
您可以使用jQuery实现此目的;
$('.s_label').each(function(){
var confirm = $(this).is(':checked');
alert(confirm);
});;