JS如何獲取RadiobuttonList的選中值


JS代碼:

<script language="javascript" type="text/javascript">
        function RadioButtonList1Changed() {
            var vRbtid = document.getElementById("RadioButtonList1");
            //得到所有radio
            var vRbtidList = vRbtid.getElementsByTagName("INPUT");
            for (var i = 0; i < vRbtidList.length; i++) {
                if (vRbtidList[i].checked) {
                    var text = vRbtid.cells[i].innerText;
                    var value = vRbtidList[i].value;
                    alert("選中項的text值為" + text + ",value值為" + value);
                }
            }
            }
    </script>

HTML:

 <asp:RadioButtonList ID="RadioButtonList1" runat="server" onClick="return RadioButtonList1Changed()">
             <asp:ListItem>1</asp:ListItem>
             <asp:ListItem>2</asp:ListItem>
             <asp:ListItem>3</asp:ListItem>
         </asp:RadioButtonList>


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM