zoukankan      html  css  js  c++  java
  • javascript RadioButtonList 選択値

    【ASPXソース】
    <%-- クリックするとアラート表示--%>
    <input id="button1" type="button" value="選択表示" 
      onclick="getCheckedRadio('<%= RadioButtonList1.ClientID %>')"/>
    
    <%-- ラジオボタンリスト--%>
    <asp:RadioButtonList ID="RadioButtonList1" runat="server">
      <asp:ListItem>AAA</asp:ListItem>
      <asp:ListItem Selected="True">BBB</asp:ListItem>
      <asp:ListItem>CCC</asp:ListItem>
    </asp:RadioButtonList>
    
    
    【javascript(jQuery)ソース】
    //この引数idはコントロールIDの文字列を渡してください。
    function getCheckedRadio(id) {
    
      //各Itemの配列を取得
      //↓javascriptならこれ
      var radio = document.getElementById(id).getElementsByTagName("input");
    
      //↓jQueryならこれ
      //var radio = $("#" + id + " :radio");
    
        for (var j = 0; j < radio.length; j++) {
    
           //選択されたラジオボタンの時
           if (radio[j].checked)
            
            //アラート表示
            alert(radio[j].value);
    
        }
    }
    
    
    
    これで、選択表示ボタンをクリックすると、「BBB」のアラートが表示されます。
    これを応用して、いろいろできそう。
    
  • 相关阅读:
    【JavaWeb】DbUtils入门之QueryRunner
    详解 hibernate mapping配置
    hibernate-mapping的各种属性配置
    Hibernate入门这一篇就够了
    记一次Sql优化过程
    ExtJs双ActionResult共用同一Js文件ID冲突解决方案
    ExtJs批量更新
    枚举初使用
    Dapper连接Oracle
    读取Excel任务列表并显示在Outlook日历上
  • 原文地址:https://www.cnblogs.com/haiy/p/4079147.html
Copyright © 2011-2022 走看看