我有一个服务器端RadioButtonList
控件,该控制呈现客户端代码。如您所见,我已经连接了客户端JavaScript,以显示单击任何无线电按钮时显示警报。这与我在线看到的示例一致。但是,当我单击任何广播按钮时,警报不会显示。控制台也没有显示任何错误。怎么了?我只能使用纯JavaScript,而不是jQuery。我正在最新的Chrome浏览器中运行此操作。
<span id="ctl00_ContentPlaceHolder1_rblApartmentType">
<input id="ctl00_ContentPlaceHolder1_rblApartmentType_0" type="radio" name="ctl00$ContentPlaceHolder1$rblApartmentType" value="1" onclick="javascript:alert('1');">
<label for="ctl00_ContentPlaceHolder1_rblApartmentType_0">Apartment</label>
<input id="ctl00_ContentPlaceHolder1_rblApartmentType_1" type="radio" name="ctl00$ContentPlaceHolder1$rblApartmentType" value="2" onclick="javascript:alert('2');">
<label for="ctl00_ContentPlaceHolder1_rblApartmentType_1">Town Home</label>
<input id="ctl00_ContentPlaceHolder1_rblApartmentType_2" type="radio" name="ctl00$ContentPlaceHolder1$rblApartmentType" value="3" checked="checked" onclick="javascript:alert('3');">
<label for="ctl00_ContentPlaceHolder1_rblApartmentType_2">Condo</label>
</span>
不一定是答案,但是对于查看,cuz有s/t奇怪的op渲染:
页面:
<asp:RadioButtonList ID="RadioButtonList1" runat="server">
<asp:ListItem Text="a" Value="1" onclick="alert('1');"></asp:ListItem>
<asp:ListItem Text="b" Value="2" onclick="alert('2');"></asp:ListItem>
</asp:RadioButtonList>
呈现为:
<table id="RadioButtonList1">
<tbody>
<tr>
<td>
<input id="RadioButtonList1_0" type="radio"
name="ctl00$MainContent$RadioButtonList1" value="1" onclick="alert('1');">
<label for="RadioButtonList1_0">a</label></td>
</tr>
<tr>
<td>
<input id="RadioButtonList1_1" type="radio"
name="ctl00$MainContent$RadioButtonList1" value="2" onclick="alert('2');">
<label for="RadioButtonList1_1">b</label></td>
</tr>
</tbody>
</table>
请注意,我也在web.config中使用了它,因此渲染时的ID并不那么疯狂(摆脱了很多诸如ctl00$...
:
<system.web>
<pages clientIDMode="Static">