![](/img/trans.png)
[英]Javascript click event not working in Blazor client side app
[英]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.