[英]Webforms - RadiobuttonLists client side click event not working
I have a server side RadioButtonList
control that renders client side code as below. 我有一个服务器端
RadioButtonList
控件,它呈现如下客户端代码。 As you can see, I have attached client side javascript to show an alert when any of the radio buttons are clicked. 如您所见,我已附加了客户端javascript,以在单击任何单选按钮时显示警报。 This is in line with the examples I saw online.
这符合我在网上看到的示例。 However, the alert doesn't show when I click any radio button.
但是,当我单击任何单选按钮时,警报不会显示。 The console doesnt show any errors either.
控制台也不显示任何错误。 What could be wrong?
有什么事吗 I can only use pure javascript and not jQuery.
我只能使用纯JavaScript,而不能使用jQuery。 I am running this in the latest Chrome browser.
我正在最新的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>
not necessarily an answer, but for viewing, cuz there's s/t weird with the op's rendering: 不一定是答案,但是对于查看来说,因为操作渲染有点奇怪:
page: 页:
<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>
renders as: 呈现为:
<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>
note, i also use this in web.config so the IDs aren't so crazy when rendered (gets rid of a lot of stuff like ctl00$...
: 请注意,我也在web.config中使用了它,因此ID呈现时并没有那么疯狂(摆脱了很多类似
ctl00$...
的东西:
<system.web>
<pages clientIDMode="Static">
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.