JQuery's values and values for html elements

Source: Internet
Author: User

Jquery assigns TEXTBOX: var str =$ ('# txt') to the value of the basic control '). val (); $ ('# txt '). val ("Set Lbl Value"); // text box, text area: $ ("# text_id "). attr ("value", ''); // clear content $ (" # text_id "). attr ("value", 'test'); // fill in the content
Jquery assigns values and values to basic controls


TEXTBOX:
Var str = $ ('# txt'). val ();


$ ('# Txt'). val ("Set Lbl Value ");


1. // text box, text area:
2. $ ("# text_id"). attr ("value", ''); // clear the content
3. $ ("# text_id"). attr ("value", 'test'); // fill in the content
LABLE:


Var str = $ ('# lbl'). text ();


$ ('# Lbl'). text ("Set lbl Value ");


1. var valradio = $ ("input [@ type = radio] [@ checked]"). val ();
2. var item = $ ('input [@ name = items] [@ checked] '). val ();
3. var checkboxval = $ ("# checkbox_id"). attr ("value ");
4. var selectval = $ ('# select_id'). val ();
1. // multiple selection box checkbox:
2. $ ("# chk_id"). attr ("checked", ''); // make it unchecked
3. $ ("# chk_id"). attr ("checked", true); // select
4. if ($ ("# chk_id"). attr ('checked') = true) // you can check whether the selected
1. Single-choice group radio:
2.
3. $ ("input [@ type = radio]"). attr ("checked", '2'); // set the project with value = 2 as the currently selected item
4.
5. // drop-down box select:
6. $ ("# select_id"). attr ("value", 'test'); // set the project with value = test as the selected item
7. $ ("<option value = 'test'> test </option> <option value = 'test2'> test2 </option> "). appendTo ("# select_id") // Add the option in the drop-down box
8. $ ("# select_id"). empty (); // clear the drop-down list
9.
10. Get the value of a set of radio selected items named (items)
11. var item = $ ('input [@ name = items] [@ checked] '). val (); // if not selected, val () = undefined
12. Get the text of the selected select item
13. var item = $ ("select [@ name = items] option [@ selected]"). text ();
14. The second element in the select drop-down box is the selected value.
15. $ ('# select_id') [0]. selectedIndex = 1;
16. The second element of the radio Group is the currently selected value.
17. $ ('input [@ name = items] '). get (1). checked = true;
18.
19. // reset the form
20. $ ("form"). each (function (){
21. reset ();
22 .});
Abstract: Jquery assigns the value of TEXTBOX: var str =$ ('# txt') to the basic control '). val (); $ ('# txt '). val ("Set Lbl Value"); // text box, text area: $ ("# text_id "). attr ("value", ''); // clear content $ (" # text_id "). attr ("value", 'test'); // fill in the content
Jquery assigns values and values to basic controls


TEXTBOX:
Var str = $ ('# txt'). val ();


$ ('# Txt'). val ("Set Lbl Value ");


1. // text box, text area:
2. $ ("# text_id"). attr ("value", ''); // clear the content
3. $ ("# text_id"). attr ("value", 'test'); // fill in the content
LABLE:


Var str = $ ('# lbl'). text ();


$ ('# Lbl'). text ("Set lbl Value ");


1. var valradio = $ ("input [@ type = radio] [@ checked]"). val ();
2. var item = $ ('input [@ name = items] [@ checked] '). val ();
3. var checkboxval = $ ("# checkbox_id"). attr ("value ");
4. var selectval = $ ('# select_id'). val ();
1. // multiple selection box checkbox:
2. $ ("# chk_id"). attr ("checked", ''); // make it unchecked
3. $ ("# chk_id"). attr ("checked", true); // select
4. if ($ ("# chk_id"). attr ('checked') = true) // you can check whether the selected
1. Single-choice group radio:
2.
3. $ ("input [@ type = radio]"). attr ("checked", '2'); // set the project with value = 2 as the currently selected item
4.
5. // drop-down box select:
6. $ ("# select_id"). attr ("value", 'test'); // set the project with value = test as the selected item
7. $ ("<option value = 'test'> test </option> <option value = 'test2'> test2 </option> "). appendTo ("# select_id") // Add the option in the drop-down box
8. $ ("# select_id"). empty (); // clear the drop-down list
9.
10. Get the value of a set of radio selected items named (items)
11. var item = $ ('input [@ name = items] [@ checked] '). val (); // if not selected, val () = undefined
12. Get the text of the selected select item
13. var item = $ ("select [@ name = items] option [@ selected]"). text ();
14. The second element in the select drop-down box is the selected value.
15. $ ('# select_id') [0]. selectedIndex = 1;
16. The second element of the radio Group is the currently selected value.
17. $ ('input [@ name = items] '). get (1). checked = true;
18.
19. // reset the form
20. $ ("form"). each (function (){
21. reset ();

22 .)};

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.