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