獲取一組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>

 


免責聲明!

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