专注收集记录技术开发学习笔记、技术难点、解决方案
网站信息搜索 >> 请输入关键词:
您当前的位置: 首页 > ASP.NET

请教在JS中如何判断RadioButtonList是否选中了其中的一项

发布时间:2011-06-22 09:34:17 文章来源:www.iduyao.cn 采编人员:星星草
请问在JS中怎么判断RadioButtonList是否选中了其中的一项
请问在JS中怎么判断RadioButtonList是否选中了其中的一项
比如:
 <asp:RadioButtonList runat="server" ID="rdoDiscount" RepeatLayout="Flow" RepeatDirection="Horizontal">
  <asp:ListItem Selected="True" Value="1">折扣</asp:ListItem>
  <asp:ListItem Value="2">价格</asp:ListItem>
  </asp:RadioButtonList>

用IS判断选择的是:折扣 还是 :价格
怎么判断?

------解决方案--------------------
HTML code
<asp:RadioButtonList runat="server" ID="rdoDiscount" RepeatLayout="Flow" RepeatDirection="Horizontal">
        <asp:ListItem Value="1">折扣 </asp:ListItem>
        <asp:ListItem Value="2">价格 </asp:ListItem>
    </asp:RadioButtonList>
    <input type="button" onclick="haveChecked()?alert('已选择'):alert('未选择');" value="check" />

    <script type="text/javascript">
    function haveChecked()
    {
        var rbl=document.getElementById('<%=rdoDiscount.ClientID %>');
        var rbls=rbl.getElementsByTagName('input');
        for(var i=0;i<rbls.length;i++)
        {
            if(rbls[i].type=='radio')
                if(rbls[i].checked) return true;
        }
        return false;
    }
    
    </script>

------解决方案--------------------
改进一下

HTML code
<asp:RadioButtonList runat="server" ID="rdoDiscount" RepeatLayout="Flow" RepeatDirection="Horizontal">
        <asp:ListItem Value="1">折扣 </asp:ListItem>
        <asp:ListItem Value="2">价格 </asp:ListItem>
    </asp:RadioButtonList>
    <input type
友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。

其他相似内容:

热门推荐: