Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 单击按钮返回动态复选框列表span ID_Javascript_Asp.net - Fatal编程技术网

Javascript 单击按钮返回动态复选框列表span ID

Javascript 单击按钮返回动态复选框列表span ID,javascript,asp.net,Javascript,Asp.net,我有一个动态的复选框列表,它创建了一个HTML表。为了简单起见,我列出了一行 <table id="checkBoxList1" border="0"> <tr> <td><span someValue="neededValue"><input id="checkBoxList1_0" type="checkbox" name="checkBoxList1$0" checked="checked" /><l

我有一个动态的
复选框列表
,它创建了一个HTML表。为了简单起见,我列出了一行

<table id="checkBoxList1" border="0">
    <tr>
        <td><span someValue="neededValue"><input id="checkBoxList1_0" type="checkbox" name="checkBoxList1$0" checked="checked" /><label for="checkBoxList1_0">TestTopic1</label></span></td>
    </tr>
</table>

现在它返回一个空值。

复选框[i].parentNode.getAttribute('someValue')
替换
跨越[i]

我建议使用jQuery。它大大简化了您的代码,例如:

<asp:Button ID="btnSubscribe" runat="server" Text="Update Subscriptions" />

$(function() {
    $('#<%=btnSubscribe.ClientID%>').click(function (e) {
        $('#<%=checkBoxList1.ClientID%> input:checked').each(function() {
            alert('Selected = ' + $(this).closest('span').attr('someValue'));
        });
        e.preventDefault();
    });
});

$(函数(){
$('#')。单击(函数(e){
$(“#输入:选中”)。每个(函数(){
警报('Selected='+$(this).closest('span').attr('someValue'));
});
e、 预防默认值();
});
});
<asp:Button ID="btnSubscribe" runat="server" Text="Update Subscriptions" />

$(function() {
    $('#<%=btnSubscribe.ClientID%>').click(function (e) {
        $('#<%=checkBoxList1.ClientID%> input:checked').each(function() {
            alert('Selected = ' + $(this).closest('span').attr('someValue'));
        });
        e.preventDefault();
    });
});