1

3 つのプレースホルダーがある 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);
}
4

2 に答える 2

2

あなたはこれを探しているかもしれません。checked「 」プロパティを使用します

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

またはjqueryを使用して、このようにプロパティを確認できます

var isChecked = $("#<%=lblIsActive.ClientID%>").is(':checked');
alert(isChecked);
于 2012-06-01T06:13:01.913 に答える
0

これは jQuery を使用して実現できます。

$('.s_label')​​​​​​.each(function(){
  var confirm = $(this).is(':checked');
  alert(confirm);
});;​
于 2012-06-01T06:00:15.153 に答える