Jquery's values and values for form elements

Source: Internet
Author: User

/* Get the text value */var textval = $ ("# text_id "). attr ("value"); // or var textval = $ ("# text_id "). val ();/* Get the value of the single-choice button */var valraio = $ ("input [type = raio]: checked "). val ();/* Get the value of a set of radio selected items named items */var item =$ ('input [name = items]: checked '). val ();/* Get the value of the check box */var checkboxval = $ ("# checkbox_id "). attr ("value");/* Get the value of the drop-down list */var selectval = $ ("# select_id "). val ();/* text box, text area */$ ("# text_id "). attr ("value", ''); // clear content $ (" # text_id "). attr ("value", 'test'); // fill in the Content/* multiple choice box checkbox */$ ("# chk_id "). attr ("checked", ''); // make it unchecked $ (" # chk_id "). attr ("checked", true); // select if ($ ("# chk_id "). attr ('checked') = true) // determines whether a single-choice group is selected/* radio */$ ("input [type = radio]"). attr ("checked", '2') // set the project with value = 2 to the currently selected item/* select */$ ("select_id") in the drop-down box "). attr ("value", 'test'); // set the value = test project to the currently selected item $("test2 "). appendTo ("# select_id") // Add option $ ("# select_id") in the drop-down box "). empty (); // clear the drop-down box/* Get the value of a set of radio selected items named items */var item =$ ('input [name = items]: checked '). val (); // if not selected, val () = undefined/* obtain the text of the selected select item */var item = $ ("select [name = items] option: selected "). text ();/* the second element of the select drop-down box is the currently 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;/* reset the form */$ ("form "). each (function (){. reset ();});

Related Article

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.