DIV CSS 佈局教程網

 DIV+CSS佈局教程網 >> 網頁腳本 >> JavaScript入門知識 >> JavaScript綜合知識 >> jQuery獲取(選中)單選,復選框,下拉框中的值
jQuery獲取(選中)單選,復選框,下拉框中的值
編輯:JavaScript綜合知識     

 本篇文章主要是對jQuery獲取(選中)單選,復選框,下拉框中的值的實現方法進行了介紹,需要的朋友可以過來參考下,希望對大家有所幫助

實例如下:    代碼如下: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>MyHtml.html</title>   <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="this is my page"> <meta http-equiv="content-type" content="text/html; charset=UTF-8">   <!--<link rel="stylesheet" type="text/css" href="./styles.css">--> <script type="text/javascript" src="jquery-1.3.min.js"></script> <script type="text/javascript"> function aa(){ // 獲取單選按鈕的值 var a = $("input[name='sex'][checked]").val(); alert(a); } function bb(){ // 若選中返回true,否則返回false var c = $("#a").attr("checked"); alert(c);   // 獲取單個復選框的值 var d = $("input[name='checkName'][checked]").val(); alert(d);   // 獲取多個復選框的值 $("input[name='checkName'][checked]").each(function(){ if(this.checked) alert($(this).val()); }); }   function checkWeek(){ //var $param = {}; $("#mPrefType").each(function(){ //    var key = $(this).attr("name"); //    if(!$param[key]) //        $param[key] = []; // 獲得value值 var value = $("##mPrefType option:selected").val(); alert(value); // 獲得需要的值 var name = $("##mPrefType option:selected").text(); alert(name); }); } </script> </head>   <body> Number:<input type = "text" value ="" name ="num1"/><br> Number:<input type = "text" value ="" name = "num2"/><br> <input type = "radio" value = "a"  name = "ss" />a <input type = "radio" value = "b"  name = "ss" />b <input type = "radio" value = "c"  name = "ss"/>c <input type = "radio" value = "d"  name = "ss" >d<br> <input type = "submit"  value = "提交"/> <br> <hr> <input type="radio" value="男" name="sex" id="1" onclick="aa()"/>男 <input type="radio" value="女" name="sex" id="0" onclick="aa()"/>女<br> <input type="button" value="您選擇的性別" onclick="aa()"/><br> <hr> <input type="checkbox" name="checkName" value="aa" id="a"/>aa <input type="checkbox" name="checkName" value="bb" id="b"/>bb <input type="checkbox" name="checkName" value="cc"/>cc <input type="checkbox" name="checkName" value="dd"/>dd<br> <input type="button" value="您選擇的值是" onclick="bb()"/> <hr> <ul> <li>請選澤</li> <li> <select id="mPrefType" name="mPrefType" class="inputS" onchange="checkWeek()"> <option value=0>請選擇:</option> <option value=1>星期一</option> <option value=2>星期二</option> <option value=3>星期三</option> <option value=4>星期四</option> <option value=5>星期五</option> <option value=6>星期六</option> <option value=7>星期日</option> </select> </li> </ul> </body> </html>   
XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved