Jqueryradio, checkbox, select, radio, checkbox, select, and related 1. obtain the value of jquery. Obtain the value of the radio button [html] $ (& quot; input [name & amp; #39; items & amp; #39;]: checked & quot ;). val (); jquery radio value, checkbox value, select value, radio selected, checkbox selected, select selected, and related 1. obtain the value of jquery. Obtain the value of the radio button [html] $ ("input [name = 'items ']: checked "). val (); get the value of a set of items selected by radio [html] var item =$ ('input [name = items] [checked] '). val (); obtain the text of the selected select item [html] var item =$ ("select [name = items] option [selected]"). text (); the second element in the select drop-down box is the currently selected value [html] $ ('# select_id') [0]. selectedIndex = 1; the second element of the radio Group is the currently selected value [html] $ ('input [name = items] '). get (1 ). checked = true; text box, text area: [html] $ ("# txt "). attr ("value"); multiple choice box checkbox: [html] $ ("# checkbox_id "). attr ("value"); single-choice radio: [html] $ ("input [type = radio] [checked]"). val (); drop-down box select: [html] $ ('# sel '). val (); 2. control Form element: text box, text area: [html] $ ("# txt "). attr ("value", ''); // clear the content $ (" # txt "). attr ("value", '11'); // multiple-choice box for filling content checkbox: [html] $ ("# chk1 "). attr ("checked", ''); // do not tick $ (" # chk2 "). attr ("checked", true); // tick if ($ ("# chk1 "). attr ('checked') = undefined) // determines whether the radio group radio has been checked: [html] $ ("input [type = radio]"). attr ("checked", '2'); // select: $ ("# sel") for the project whose value is set to 2 "). attr ("value", '-sel3'); // set the value =-sel3 project as the currently selected item $ (" 1111 2222"). AppendTo ("# sel") // Add option $ ("# sel") in the drop-down box "). empty (); // clear the drop-down list. Note: When $ ("# id") is used to obtain the input element of the page, $ ("# id") is found "). the value cannot be obtained. Later, with the help of the great Baidu, the cause of the problem was found: $ ("") is a jquery object, instead of a dom element value, jquery corresponds to the dom element attribute val (): obtains the current value of the First Matching element. Val (val): sets the value of each matching element. Therefore, the code should be written as follows: [html]; Value: val = $ ("# id") [0]. value; value: $ ("# id") [0]. value = "new value"; or $ ("# id "). val ("new value"); or you can: val = $ ("# id "). attr ("value ");
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.