js获取radiobuttonlist value 和 text 值

时间:2022-08-28 19:34:14
  function check() {
            var ckl = document.getElementById("RadioButtonList1");
            var ck = ckl.getElementsByTagName("input");
            for (var i = 0; i < ck.length; i++) {
                if (ck[i].checked) {
                    var text = ckl.cells[i].innerText;
                    var value = ck[i].value;

                }

            }
        }
 <div>
   
    <asp:RadioButtonList ID="RadioButtonList1" runat="server">
    <asp:ListItem Value="我是value1">我是text1</asp:ListItem>
    <asp:ListItem Value="我是value2">我是text2</asp:ListItem>
    <asp:ListItem Value="我是value3">我是text3</asp:ListItem>
    </asp:RadioButtonList>
     <asp:Button ID="Button2" runat="server" Text="js获取选中值" OnClientClick="check()" />
      </div>