jquery operation Select (value, set selected)

Source: Internet
Author: User

every time the operation of the Select, always to come out to turn over the information, as a summary of their own, after the turn over here. Like<Select class="selector"></Select>1, set the value for Pxx to select $ (". Selector"). Val ("Pxx");2, set text to Pxx to select $ (". Selector"). Find ("option[text= ' pxx ']"). attr ("selected",true); Here is the use of a bracket, preceded by the attribute name in parentheses, without quotation marks. In many cases, the use of brackets can make logic very simple. 3, gets the value of the currently selected item $ (". Selector"). Val ();4, gets the text $ of the currently selected item (". Selector"). Find ("option:selected"). text (); Using a colon here, mastering its usage and extrapolate will also make the code concise. There are many times when a select cascade is used, that is, the value of the second select changes with the value selected in the first select. This is very simple in jquery. such as: $ (". Selector1"). Change (function () {//clear the second one first .      $(". Selector2"). empty (); //in real-world applications, the option here is typically generated by looping multiple      varOption = $ ("<option>"). Val (1). Text ("Pxx"); $(". Selector2"). Append (option);});

there are many times when a select cascade is used, that is, the value of the second select changes with the value selected in the first select. This is very simple in jquery. such as: $ (". Selector1"). Change (function () {//clear the second one first .      $(". Selector2"). empty (); //in real-world applications, the option here is typically generated by looping multiple      varOption = $ ("<option>"). Val (1). Text ("Pxx"); $(". Selector2"). Append (option);}); http://www.cnblogs.com/yaoshiyou/archive/2010/08/24/1806939.htmljquery Gets the text and value of the Select selection: syntax Explanation:1. $("#select_id"). Change (function () {//code ...}); //Add an event for Select, which is triggered when one of the items is selected2.varchecktext=$ ("#select_id"). Find ("option:selected"). text ();//gets the text selected by the Select3.varcheckvalue=$ ("#select_id"). Val ();//gets the value selected by Select4.varcheckindex=$ ("#select_id").Get(0). SelectedIndex;//gets the index value of the select selection5.varmaxindex=$ ("#select_id Option:last"). attr ("Index");//Gets the maximum index value of the Selectjquery Sets the text and value of select selection: syntax Explanation:1. $("#select_id").Get(0). selectedindex=1;//Set the Select index value to 1 to select2. $("#select_id"). Val (4);//Sets the value of select to 4 for the item selected3. $("#select_id option[text= ' jQuery ')"). attr ("selected",true);//set the text value of select to the item selected for jqueryjquery Add/Delete option for select: Syntax explanation:1. $("#select_id"). Append ("<option value= ' value ' >Text</option>");//append an option to the Select ( drop-down item)2. $("#select_id"). Prepend ("<option value= ' 0 ' > Please select </option>");//Insert an option for select (first position)3. $("#select_id Option:last"). Remove ();//Delete index value in select maximum option (last)4. $("#select_id option[index= ' 0 ']"). Remove ();//Delete option with index value 0 in select (first)5. $("#select_id option[value= ' 3 ']"). Remove ();//Delete option for value= ' 3 ' in select5. $("#select_id option[text= ' 4 ']"). Remove ();//Delete option for text= ' 4 ' in selecthttp://www.cnblogs.com/SAL2928/archive/2008/10/28/1321285.htmljquery Radio value, checkbox value, select Value, Radio selected, CheckBox selected, select selected, and its related to get a set of radio values of the selected itemvarItem = $ ('input[name=items][checked]'). Val (); Gets the text of the Select selected itemvarItem = $ ("Select[name=items] option[selected]"). text (); The second element of the Select drop-down box is the current check value of $ ('#select_id')[0].selectedindex =1; Radio the second element of the radio group is the currently selected value $ ('Input[name=items]').Get(1).checked=true; Gets the value: text box, text area: $ ("#txt"). attr ("value"); Multi 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 Content$("#txt"). attr ("value",' One');//Populating contentMulti Marquee checkbox: $ ("#chk1"). attr ("checked","');//no tick .$("#chk2"). attr ("checked",true);//Tickif($("#chk1"). attr ('checked') ==undefined)//To determine if a tick has been madeRadio Group Radio: $ ("Input[type=radio]"). attr ("checked",'2');//set the value=2 item as the currently selected itemdrop-down boxSelect$"#sel"). attr ("value",'-sel3');//set the VALUE=-SEL3 item as the currently selected item$("<option value= ' 1 ' >1111</option><option value= ' 2 ' >2222</option>"). AppendTo ("#sel")//option to add a drop-down box$("#sel"). empty ();//empty drop-down box

jquery operation Select (value, set selected)

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.