JQuery select checkbox radio summary, jquerycheckbox

Source: Internet
Author: User

JQuery select checkbox radio summary, jquerycheckbox

JQuery is a powerful tool, so I need to find the most convenient method.

Select add, delete, modify, and query:

Select query:
1. val value:
$ ("# Selectid"). val (); // the most convenient
2. text value:
$ ("# Selectid option: selected"). text (); // the most convenient
Or $ ("# selectid"). find ("option: selected"). text ()
3. Index value:
$ ("# Selectid"). get (0). selectedIndex; // the most convenient

Select change:
1. val value:
$ ("# Selectid"). val ("xxx"); // the most convenient
Or $ ("# selectid"). attr ("value", "xxx ");
2. text value:
$ ("# Selectid option [text = abc]"). attr ("selected", true); // the most convenient
Or $ ("selectid option: contains (xxx)"). attr ("selected", true );
3. index value:
$ ("# Select option [index = 1]"). attr ("selected", true); // the most convenient

Select increment:
$ ("# Selectid"). append ($ ("<opiton value = '0'> JOHN </option>"); // these two are quite common.
$ ("# Selectid"). prepend ($ ("<opiton value = '0'> JOHN </option> "));

Select Delete:
Clear: $ ("# selectid"). empty (); // general values are cleared before insertion.
Partially delete:
$ ("# Selectid option: gt (0)"). remove (); // because the first row is sometimes cleared by tHead
$ ("# Selectid option [value = xxx]"). remove ();
$ ("# Selectid option [text = xxx]"). remove ();
$ ("# Selectid option [index = xxx]"). remove ();
Select not selected
$ ("# Selectid"). attr ("selected", true );
$ ("# Selectid"). attr ("selected", false );

Radio query:
$ ("# Radioid"). val ();
$ ("# Radioid [name = xxx]"). val ();
$ ("# Radioid [id = xxx]"). val ();
Radio change:
$ ("Radioid [value = xxx]"). attr ("checked", true );
$ ("Radioid: eq (1)"). attr ("checked", true );
Radio deletion:
$ ("Radioid"). remove ();

Checkbox query:
$ ("# Checkboxid"). val ();
$ ("# Checkboxid [name = xxx]"). val ();
$ ("# Checkboxid [id = xxx]"). val ();
Change Checkbox:
$ ("Checkboxid [value = xxx]"). attr ("checked", true );
$ ("Checkboxid: eq (1)"). attr ("checked", true );
$ (": Button"). bind ("click", function (){
$ (": Checkbox"). each (function (){
// $ (This). attr ("checked ",! $ (This). attr ("checked"); click the checkbox button to select it;
// $ (This). attr ("checked", true); click the checkbox button to select all;
$ (This). attr ("checked", false); no checkbox is selected;
// If ($ (this). attr ("checked") = true) {alert ($ (this). val ()} selected value
// If ($ (this). attr ("checked") = false) {alert ($ (this). val ()} unselected Value
})
})
})
Checkbox deletion:
$ ("Checkboxid"). remove ();


Txt text box query:
$ ("# Txtid"). val ();
Modify the txt text box:
$ ("# Txtid"). val ("xx ");
Delete txt text box:
$ ("# Txtid"). val ("");


Jquery radio, checkbox, select, radio, checkbox, select, and related
Obtains the value of a set of radio selected items.
Var item = $ ('input [name = items] [checked] '). val ();
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 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

 


How does Jquery obtain the radio select checkbox text box?

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 Group is the currently selected value.
$ ('Input [@ name = items] '). get (1 ). checked = true; 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 element:
Text Box, text area: $ ("# txt"). attr ("value", ''); // clear the content
$ ("# Txt "). attr ("value", '11'); // multiple-choice box for filling content checkbox: $ ("# chk1 "). attr ("checked", ''); // do not check
$ ("# Chk2"). attr ("checked", true); // check
If ($ ("# chk1 "). attr ('checked') = undefined) // determines whether the radio group radio has been checked: $ ("input [@ type = radio]"). attr ("checked", '2'); // set the project with value = 2 to the selected one (incorrect)
$ ("Input [@ name = radio_s] [@ value = 16]"). attr ("checked", true); (tested) drop-down box select: $ ("# sel "). attr ("value", '-sel3'); // you can specify the value =-sel3 as the 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 box $ ("# select1") [0]. options (index ). selected = true; & amp; #4 ...... remaining full text>

How does Jquery obtain the radio select checkbox text box?

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 Group is the currently selected value.
$ ('Input [@ name = items] '). get (1 ). checked = true; 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 element:
Text Box, text area: $ ("# txt"). attr ("value", ''); // clear the content
$ ("# Txt "). attr ("value", '11'); // multiple-choice box for filling content checkbox: $ ("# chk1 "). attr ("checked", ''); // do not check
$ ("# Chk2"). attr ("checked", true); // check

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.