jquery Gets the value of the Select,dropdownlist,checkbox drop-down list box

Source: Internet
Author: User

jquery Gets the text and value selected by select:Syntax Explanation:1. $ ("#select_id"). Change (function () {//code ...}); Add an event for Select, which is triggered when one of the items is selected2. Var checktext=$ ("#select_id"). Find ("option:selected"). Text (); Gets the text selected by the Select3. Var checkvalue=$ ("#select_id"). Val (); Gets the value selected by Select4. Var checkindex=$ ("#select_id"). Get (0). SelectedIndex; Gets the index value of the select selection5. Var maxindex=$ ("#select_id option:last"). attr ("index"); Gets the maximum index value of the Selectjquery Sets the text and value selected for select: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/Remove 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.html jquery Radio value, checkbox value, select Value, Radio selected, CheckBox selected, select selected, and its relatedgets the value of a set of radio selected itemsvar item = $ (' input[@name =items][@checked] '). Val ();gets the text of the Select selected itemvar 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;Radio The second element of a radio group is the currently selected value$ (' input[@name =items] '). Get (1). checked = true; Get 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 Contents$ ("#txt"). attr ("value", ' 11 ');//fill content multiple Marquee checkbox: $ ("#chk1"). attr ("Checked", "");//No tick$ ("#chk2"). attr ("Checked", true);//Tickif ($ ("#chk1"). attr (' checked ') ==undefined)//Determine if a tick has been made Radio Group Radio: $ ("input[@type =radio]"). attr ("Checked", ' 2 ');//Set value=2 for the currently selected itemDrop- down box select: $ ("#sel"). attr ("value", '-sel3 ');//Set the VALUE=-SEL3 item as the current selection$ ("<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 ----------------------------------------------------------------------------------------------------  //Traverse option and Add, remove optionfunction Changeshipmethod (shipping) {var len = $ ("select[@name =ishiptype] option"). Lengthif (shipping.value! = "CA") {$ ("select[@name =ishiptype] option"). each (function () {if ($ (this). val () = = 111) {$ (this). Remove ();}});}else{$ ("<option value= ' 111 ' >ups ground</option>"). AppendTo ($ ("select[@name =ishiptype]"));}}  //Get the Select value of the dropdown $ (#testSelect option:selected '). Text ();or $ ("#testSelect"). Find (' option:selected '). Text ();or $ ("#testSelect"). Val ();//////////////////////////////////////////////////////////////////a bad memory can be collected:1, drop-down box: var cc1 = $ (". FORMC select[@name = ' country '] option[@selected]"). text ();////Get the selected item (note the space in the middle) of the drop-down menuvar cc2 = $ ('. FORMC select[@name = "Country"]). Val ();//Get the value of the selected item in the drop-down menuvar cc3 = $ ('. FORMC select[@name = "Country"]). attr ("id");//Get the value of the ID property of the selected item in the drop-down menu$ ("#select"). empty ();//Empty the drop-down box//$ ("#select"). HTML (");$ ("<option value= ' 1 ' >1111</option>"). AppendTo ("#select")//option to add a drop-down box A little explanation:1.select[@name = ' country '] option[@selected] means having the Name property,and the option element with the selected attribute in the Select element with the attribute value of ' country ';you can see that there is an @ at the beginning of the property is followed by.  2, Radio box:$ ("input[@type =radio][@checked]"). Val ();//Get the value of the selected item in the Radio box (note that there are no spaces in the middle)$ ("input[@type =radio][@value =2]"). attr ("Checked", ' checked ');//Set the Radio box to value=2 the selected state. (note there is no space in the middle) 3, check box:$ ("input[@type =checkbox][@checked]"). Val ();//Gets the value of the check box for the first item selected$ ("input[@type =checkbox][@checked]"). each (function () {////Because the check box is generally selected as multiple, you can loop the outputalert (This). Val ());}); $ ("#chk1"). attr ("Checked", "");//Not ticked$ ("#chk2"). attr ("Checked", true);//Tickif ($ ("#chk1"). attr (' checked ') ==undefined) {}//Determine if a tick has been made  Of Course the jquery selector is powerful. There are many other ways. <script src= "jquery-1.2.1.js" type= "Text/javascript" ></script><script language= "javascript" type= "Text/javascript" >$ (document). Ready (function () {$ ("#selectTest"). Change (function (){//alert ("Hello");//alert ($ ("#selectTest"). attr ("name"));//$ ("a"). attr ("href", "xx.html");//window.location.href= "xx.html";//alert ($ ("#selectTest"). Val ());Alert ($ ("#selectTest option[@selected]"). text ());$ ("#selectTest"). attr ("Value", "2"); });});</script>  <a href= "#" >aaass</a> <!-- drop-down box--<select id= "selecttest" name= "Selecttest" ><option value= "1" >11</option><option value= "2" >22</option><option value= "3" >33</option><option value= "4" >44</option><option value= "5" >55</option><option value= "6" >66</option></select>jquery 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 itemvar item = $ (' input[@name =items][@checked] '). Val ();gets the text of the Select selected itemvar 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;Radio The second element of a radio group is the currently selected value$ (' input[@name =items] '). Get (1). checked = true;Get 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 Contents$ ("#txt"). attr ("value", ' 11 ');//fill contentmultiple Marquee checkbox: $ ("#chk1"). attr ("Checked", "");//No tick$ ("#chk2"). attr ("Checked", true);//Tickif ($ ("#chk1"). attr (' checked ') ==undefined)//Determine if a tick has been madeRadio Group Radio: $ ("input[@type =radio]"). attr ("Checked", ' 2 ');//Set value=2 for the currently selected itemDrop- down box select: $ ("#sel"). attr ("value", '-sel3 ');//Set the VALUE=-SEL3 item as the current selection$ ("<optionvalue= ' 1 ' & gt;1111</option><optionvalue= ' 2 ' >2222</option& gt;"). AppendTo ("#sel")//option to add a drop-down box$ ("#sel"). empty ();//Empty drop-down box gets the value of a set of radio selected itemsvar item = $ (' input[@name =items][@checked] '). Val ();gets the text of the Select selected itemvar 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;Radio The second element of a radio group is the currently selected value$ (' input[@name =items] '). Get (1). checked = true;Get 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 Contents$ ("#txt"). attr ("value", ' 11 ');//fill contentmultiple Marquee checkbox: $ ("#chk1"). attr ("Checked", "");//No tick$ ("#chk2"). attr ("Checked", true);//Tickif ($ ("#chk1"). attr (' checked ') ==undefined)//Determine if a tick has been madeRadio Group Radio: $ ("input[@type =radio]"). attr ("Checked", ' 2 ');//Set value=2 for the currently selected itemDrop- down box select: $ ("#sel"). attr ("value", '-sel3 ');//Set the VALUE=-SEL3 item as the current selection$ ("<option value= ' 1 ' >1111</option><option value= ' 2 ' >2222</option>"). AppendTo ("#sel") option to add a drop-down box$ ("#sel"). empty ();//Empty drop-down boxreprint: http://www.cnblogs.com/shengxiang/archive/2011/09/06/2168557.html

jquery Gets the value of the Select,dropdownlist,checkbox drop-down list box

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.