繁体   English   中英

Webforms-RadiobuttonLists客户端单击事件不起作用

[英]Webforms - RadiobuttonLists client side click event not working

我有一个服务器端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>

不一定是答案,但是对于查看来说,因为操作渲染有点奇怪:

页:

<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">

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM