jquery gets (checked) radio, check box, drop-down box value _jquery

Source: Internet
Author: User

Examples are as follows:

Copy Code code as follows:

<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" >
<title>MyHtml.html</title>

<meta http-equiv= "keywords" content= "keyword1,keyword2,keyword3" >
<meta http-equiv= "description" content= "This are 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 () {
Get the value of a radio button
var a = $ ("Input[name= ' sex '][checked]"). Val ();
alert (a);
}
function bb () {
Returns True if checked, otherwise returns false
var C = $ ("#a"). attr ("checked");
alert (c);

Get the value of a single check box
var d = $ ("input[name= ' CheckName '][checked]"). Val ();
alert (d);

Get values for multiple check boxes
$ ("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] = [];
Get value
var value = $ ("# #mPrefType option:selected"). Val ();
alert (value);
Get the value you want
var name = $ ("# #mPrefType option:selected"). Text ();
alert (name);
});
}
</script>

<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 = "Submit"/> <br>
<input type= "Radio" value= "male" name= "Sex" id= "1" onclick= "AA ()"/> Male
<input type= "Radio" value= "female" name= "sex" id= "0" onclick= "AA ()"/> Female <br>
<input type= "button" value= "Your selected Sex" onclick= "AA ()"/><br>
<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"/&GT;CC
<input type= "checkbox" Name= "CheckName" value= "DD"/>dd<br>
<input type= "button" value= "The value you selected is" onclick= "BB ()"/>
<ul>
<li> Please select Ze </li>
<li>
<select id= "Mpreftype" name= "Mpreftype" class= "inputs" onchange= "Checkweek" () >
<option value=0> Please select:</option>
<option value=1> Monday </option>
<option value=2> Tuesday </option>
<option value=3> Wednesday </option>
<option value=4> Thursday </option>
<option value=5> Friday </option>
<option value=6> Saturday </option>
<option value=7> Sunday </option>
</select>
</li>
</ul>
</body>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.