检索网格视图中复选框的选中属性

Retrieve the checked property of checkboxes in Gridview

本文关键字:属性 复选框 视图 检索 网格      更新时间:2023-09-26

>我有一个aspx页面,其中有三个占位符。现在我在每个占位符内都有复选框。如何在客户端检索复选框的选中属性。我尝试了以下代码,但它不起作用。

<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);
}

您可能正在寻找这个。 使用"checked"属性

var isChecked =  document.getElementById('<%=lblIsActive.ClientID%>').checked;
alert(isChecked);

或者通过使用jQuery,你可以像这样检查属性

var isChecked = $("#<%=lblIsActive.ClientID%>").is(':checked');
alert(isChecked);

你可以使用 jQuery 来实现这一点;

$('.s_label')​​​​​​.each(function(){
  var confirm = $(this).is(':checked');
  alert(confirm);
});;​