打赏

获取一组radio按钮选中的值Value

1、效果

 

2、HTML代码

 

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm6.aspx.cs" Inherits="MvcAppTest.WebForm6" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
    <script src="Easyui/jquery-1.7.2.min.js"></script>
    <script type="text/javascript">       
        function setCheck(pd) {
            var radios = document.getElementsByName("address");
            for (var i = 0; i < radios.length; i++) {              
                if (radios[i].value==pd)
                {
                    radios[i].checked = true;
                }
            }
        }
        function show() {
            var radios = document.getElementsByName("address");
            for (var i = 0; i < radios.length; i++) {
                if (radios[i].checked) {
                    alert(radios[i].value);
                }
            }
        }
    </script>
</head>
<body>
 <form id="form1" runat="server">
    <div>
     <input type="radio" name="address" value="0" checked="checked" />苹果&nbsp;&nbsp;&nbsp;
     <input type="radio" name="address" value="1" />香蕉&nbsp;&nbsp;&nbsp;
     <input type="radio" name="address" value="2" />葡萄
    <div>
        <input type="button" onclick="setCheck(1)" value="设置选中状态" />
    </div>
       <div>
           <input type="button" onclick="show()" value="获取选中的值" />
       </div>
    </div>  
  </form>
</body>
</html>

 

posted @ 2019-01-08 16:28  学习靠自己  阅读(4005)  评论(0编辑  收藏  举报