Jquery radio value, checkbox value, select value, Radio selected value

Source: Internet
Author: User

1. Check whether checkbox is selected

$ ("Ul Li input"). Each (function (){
If ($ (this). ATTR ("checked") = true ){
Arr. Push ($ (this). ATTR ("value "));
}
});
Alert (ARR. tostring ());

2. Obtain the radio value.

Old jquery version

Var_name = $ ("input [@ name = 'Radio _ name']: checked"). Val ();

Versions later than jquery 1.3

Var_name = $ ("input [name = 'Radio _ name']: checked"). Val ();
The difference is that the old version has @.

Jquery radio value, checkbox value, select value, Radio selected,

VaR item = $ ('input [@ name = items] [@ checked] '). Val ();
Obtain the text of the selected select item.

VaR item = $ ("select [@ name = items] Option [@ selected]"). Text ();
The second element in the select drop-down box is the selected value.

$ ('# Select_id') [0]. selectedindex = 1;
The second element of the radio Radio Group is the currently selected value.

$ ('Input [@ name = items] '). Get (1). Checked = true;
Get value:

Text Box, text area: $ ("# TXT"). ATTR ("value ");

Multiple choice box checkbox: $ ("# checkbox_id"). ATTR ("value ");

Radio Group radio: $ ("input [@ type = radio] [@ checked]"). Val ();

Drop-down box select: $ ('# sel'). Val ();

Control form elements:

Text Box, text area: $ ("# TXT"). ATTR ("value", "); // clear the content

$ ("# TXT"). ATTR ("value", '11'); // fill in the content
Multiple choice box checkbox: $ ("# CHK1"). ATTR ("checked", "); // do not check

$ ("# CHK2"). ATTR ("checked", true); // check

If ($ ("# CHK1"). ATTR ('checked') = undefined) // you can check whether the checked has been checked.
Radio Group radio: $ ("input [@ type = radio]"). ATTR ("checked", '2'); // set the project with value = 2 as the currently selected item
Drop-down box select: $ ("# Sel"). ATTR ("value", '-sel3'); // set the value =-sel3 project to the currently selected item

$ ("<Optionvalue = '1'> 1111 </option> <optionvalue = '2'> 2222 </option>"). appendto ("# sel") // Add
Option in the drop-down list

$ ("# Sel"). Empty (); // clear the drop-down list
Obtains the value of a set of Radio selected items.

VaR item = $ ('input [@ name = items] [@ checked] '). Val ();
Obtain the text of the selected select item.

VaR item = $ ("select [@ name = items] Option [@ selected]"). Text ();
The second element in the select drop-down box is the selected value.

$ ('# Select_id') [0]. selectedindex = 1;
The second element of the radio Radio Group is the currently selected value.

$ ('Input [@ name = items] '). Get (1). Checked = true;
Get value:

Text Box, text area: $ ("# TXT"). ATTR ("value ");
Multiple choice box checkbox: $ ("# checkbox_id"). ATTR ("value ");
Radio Group radio: $ ("input [@ type = radio] [@ checked]"). Val ();
Drop-down box select: $ ('# sel'). Val ();
Control form elements:

Text Box, text area: $ ("# TXT"). ATTR ("value", "); // clear the content
$ ("# TXT"). ATTR ("value", '11'); // fill in the content
Multiple choice box checkbox: $ ("# CHK1"). ATTR ("checked", "); // do not check
$ ("# CHK2"). ATTR ("checked", true); // check
If ($ ("# CHK1"). ATTR ('checked') = undefined) // you can check whether the checked has been checked.
Radio Group radio: $ ("input [@ type = radio]"). ATTR ("checked", '2'); // set the project with value = 2 as the currently selected item
Drop-down box select: $ ("# Sel"). ATTR ("value", '-sel3'); // set the value =-sel3 project to the currently selected item
$ ("<Option value = '1'> 1111 </option> <option value = '2'> 2222 </option> "). appendto ("# sel") // Add the option in the drop-down box
$ ("# Sel"). Empty (); // clear the drop-down list

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.