如何检查PageLoad后是否选择了RadioButton-Item? [英] How to Check if RadioButton-Item is selected after PageLoad?

查看:166
本文介绍了如何检查PageLoad后是否选择了RadioButton-Item?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

My RadioButtonList是用纯asp.net创建的,如下所示:

My RadioButtonList is created with pure asp.net like this:

<asp:RadioButtonList ID="RadioButtonListGutscheinArt" Visible="true" runat="server" ClientIDMode="Static">
     <asp:ListItem ID="ListItemZugAbonnement" ClientIDMode="Static" Value="1" />
     <asp:ListItem ID="ListItemBestellungHalbtax" ClientIDMode="Static" Text="Bestellung Halbtax" Value="2" />
</asp:RadioButtonList>

当我的页面重新加载时, ListItemBestellungHalbtax 将被选中。现在我想检查它是否实际上是用javascript选中的。我试过这样:

When my page reloads, the ListItemBestellungHalbtax will be selected. Now i want to check if it's actually selected with javascript. I tried it like this:

    if ($('#ListItemBestellungHalbtax').is(":checked")) 
    {
         //do whatever
    }

没有成功..有什么建议么?

With no success.. Any suggestions?

可能它不起作用,因为ListItem-Selection没有保存。即使很难看清楚它已被选中....

Maybe it doesnt work, because the ListItem-Selection is not "saved". Even tough it is clearly visible that it's selected....

推荐答案

创建时:

<asp:RadioButtonList ID="RadioButtonListGutscheinArt" Visible="true" runat="server" ClientIDMode="Static">
     <asp:ListItem ID="ListItemZugAbonnement" ClientIDMode="Static" Value="1" />
     <asp:ListItem ID="ListItemBestellungHalbtax" ClientIDMode="Static" Text="Bestellung Halbtax" Value="2" />
</asp:RadioButtonList>

它实际上是这样的:

<table id="RadioButtonListGutscheinArt" border="0">
    <tbody><tr>
        <td><span clientidmode="Static" id="ListItemZugAbonnement"><input id="RadioButtonListGutscheinArt_0" type="radio" name="ctl00$main$RadioButtonListGutscheinArt" value="1"><label for="RadioButtonListGutscheinArt_0">1</label></span></td>
    </tr><tr>
        <td><span clientidmode="Static" id="ListItemBestellungHalbtax"><input id="RadioButtonListGutscheinArt_1" type="radio" name="ctl00$main$RadioButtonListGutscheinArt" value="2"><label for="RadioButtonListGutscheinArt_1">Bestellung Halbtax</label></span></td>
    </tr>
</tbody></table>

所以请将条件更改为:

 if ($('#ListItemBestellungHalbtax input').is(":checked")) {
        //do whatever
    }

它可以起作用。

这篇关于如何检查PageLoad后是否选择了RadioButton-Item?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆