This article is mainly on the js,jquery get Select,dropdownlist,checkbox drop-down list box value (sample code) is introduced, the need for friends can come to the reference, I hope to help you.
jquery Gets the Select selected text and value: syntax explanation: 1. $ ("#select_id"). Change (function () {//code ...}); //Add event for Select, triggering 2 when one of the items is selected. var checktext=$ ("#select_id"). Find ("option:selected"). Text (); //gets the text 3 of the Select selection. var checkvalue=$ ("#select_id"). Val (); //gets the value 4 of the Select selection. var checkindex=$ ("#select_id"). Get (0). SelectedIndex; //gets the index value of select selected 5. var maxindex=$ ("#select_id option:last"). attr ("index"); //Gets the Select Maximum index value jquery setting Select selected text and value: syntax: 1. $ ("#select_id"). Get (0). selectedindex=1; //Set the Select index value of 1 to check 2. $ ("#select_id"). Val (4); //Set item with value of 4 for select 3. $ ("#select_id option[text= ' jQuery ']"). attr ("selected", true); //Set Select's text value to jquery's entry check jquery Add/Remove option: syntax explanation: 1. $ ("#select_id"). Append ("<option value= ' value ' >Text</option>"); //appends an option (dropdown) 2 to the Select. $ ("#select_id"). Prepend ("<option value= ' 0 ' > Please selectOptional </option> "); //Inserts an option (first position) 3 for the Select. $ ("#select_id option:last"). Remove (); //deletes the index value maximum option (last) 4 in Select. $ ("#select_id option[index= ' 0 ']"). Remove (); //deletes the option (first) 5 with index value 0 in the Select. $ ("#select_id option[value= ' 3 ']"). Remove (); //deletes the option 5 of value= ' 3 ' in the Select. $ ("#select_id option[text= ' 4 ']"). Remove (); //deletes the option jquery radio value of text= ' 4 ' in Select, CheckBox value, select Value, Radio Select, CheckBox selected, select selected, and related Get a set of radio the value of the selected item var item = $ (' input[@name =items][@checked] '). Val (); Get text for select selected 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; Radio The second element of the radio group is the currently selected value $ (' input[@name =items] '). Get (1). checked = true; Get value: text box, text area: $ ("#txt"). attr ("value"); multiple-selection box checkbox:$ ("#checkbox_id"). attr ("value") ; Radio Group Radio: $ ("input[@type =radio][@checked]"). Val (); dropdown BoxSelect: $ (' #sel '). Val (); Control form elements: text box, text area: $ ("#txt"). attr ("Value", "");/empty content & nbsp $ ("#txt"). attr ("value", ' 11 ');/fill content Multi-selection box checkbox: $ ("#chk1"). attr ("Checked", ""); $ ("#chk2") attr ("checked", true);/tick &N Bsp if ($ ("#chk1"). attr (' checked ') ==undefined)//Determine if it has been ticked Radio Group Radio: $ ("input[@type =radio]"). attr ("Checked", ' 2 ');//Set value=2 item to the current Check dropdown box select: $ (" #sel "). attr (" value ", '-sel3 ');//Set VALUE=-SEL3 project for current selected $ (" <option value= ' 1 ' >1111</option><option value= ' 2 ' >2222</option> '). Appendto ("#sel")// Add dropdown box option $ ("#sel"). Empty ()//Empty dropdown box ------- ------------------------------------------------------------ //traverse option and Add, remove option function Changeshipmethod (shipping) { var len = $ ("select[@name =ishiptype] option") .length if (shipping.value!= "CA") { $ ("select[@name = Ishiptype] Option ". each (the function () { if ($ (this). val () = () { $ (this). Remove (); } }); } else{ $ ("<option value= ' >ups ground</option>"). Appendto ($ ("select[@name =ishiptype]"); } } //Get dropdown selection $ (#testSelect option:selected '). Text (); or $ ("#testSelect" ). Find (' option:selected '). Text (); or $ ("#testSelect"). Val (); ///////////////////////////////////////// Bad memory can be collected under: 1, dropdown box: var cc1 = $ (". FORMC select[@name = ' country ' ] option[@selected] "). Text (); Gets the text of the selected item of the Drop-down menu (note that there are spaces in the middle) var CC2 = $ ('. FORMC select[@name = ' country '] '). Val (); Gets the value of the selected item for the Drop-down menu var cc3 = $ ('. FORMC select[@name = ' country '] '). attr ("id"); Get the nextThe id attribute value $ ("#select") for the selected item of the Pull menu. Empty ()//Empty Drop-down box//$ ("#select"). HTML ("); $ (" <option value= ' 1 ' >1111 </option> "). Appendto (" #select ")//Add Drop-down box option explain: 1.select[@name = ' country '] option[@ Selected] represents an option element with a selected attribute in the Select element with the Name property, and the property value of ' country '; can see that a @ begins with a property that follows. 2, Radio box: $ ("input[@type =radio][@checked]"). Val (); Gets the value of the selection of the radio box (note that there are no spaces in the middle) $ ("input[@type =radio][@value =2]"). attr ("Checked", ' checked '); Sets the value=2 of the radio box to the selected state. (Note that there are no spaces in between) 3, check box: $ ("input[@type =checkbox][@checked]"). Val (); The value of the first item selected for the check box $ ("input[@type =checkbox][@checked]"). each (function () {//The check box is typically selected for more than one, so you can loop out alert ($ (this). Val ()); }); $ ("#chk1"). attr ("Checked", "");//Do not tick $ ("#chk2"). attr ("Checked", true) ;//tick if ($ ("#chk1"). attr (' checked ') ==undefined) {}//To determine if a check has been ticked of course the jquery selector is powerful. There are many 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> < !--dropdown 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 related to get a set of radio values var item = $ (' input[@name =items][@checked] '). Val (); Gets the text of the Select selected item var item = $ ("select[@name =items] option[@selected]"). Text (); The second element of the Select Drop-down box is the current selected value $ (' #select_id ') [0].selectedindex = 1; Radio The second element of a single selection group is the currently selected value $ (' input[@name =items] '). Get (1). Checked = true; Get value: text box, text area: $ ("#txt"). attr ("value"); multiple marquee checkbox:$ ("#checkbox_id"). attr (" Value "); Radio: $ (" input[@type =radio][@checked] "). Val (); dropdown box select: $ (' #sel '). Val (); Control table cell element: text box, text area: $ ("#txt"). attr ("Value", "");/empty content $ ("#txt"). attr ("value", ' 11 ');/fill content Multi-Marquee checkbox: $ ("#chk1"). attr ("Checked", "");//Do not tick $ ("#chk2"). attr ("Checked", true);/tick if ($ ("#chk1"). attr (' checked ') ==undefined)//Judge whether the check has been ticked Radio Group Radio: $ ("input[@type =radio]"). attr ("Checked", ' 2 ');/set value= 2 items are currently selected dropdown box select: $ ("#sel"). attr ("value", '-sel3 ');//Set VALUE=-SEL3 item is current selected $ ("< Optionvalueoptionvalue= '1 ' >1111</option><optionvalueoptionvalue= ' 2 ' >2222</option> '). Appendto ("#sel")// Add option $ ("#sel") to the Drop-down box. Empty ()//Empty dropdown box Get a set of radio selected values var item = $ (' input[@name =items][@ Checked]. val (); Gets the text of the Select selected 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; Radio The second element of the radio group is the current selected value $ (' input[@name = Items]. Checked = true; Get value: text box, text area: $ ("#txt"). attr ("value"); multi-selection box checkbox:$ ("# checkbox_id "). attr (" value "); Radio Group Radio: $ (" input[@type =radio][@checked] "). Val (); drop-down box select: $ (' #sel '). Val (); Control table cell: text box, text area: $ ("#txt"). attr ("Value", "");/empty content $ ("#txt"). attr ("value", ' 11 '); Fill content Multi-marquee checkbox: $ ("#chk1"). attr ("Checked", "");/no tick $ ("#chk2"). attr ("Checked", true);/tick if ( "#chk1"). attr (' checked ') ==undefined)//Determine if the check has been ticked Radio Group Radio: $ ("input[@type =radio]"). attr ("Checked", ' 2 '//Set the value=2 item to the current Check dropdown box select: $ ("#sel"). attr ("value", '-sel3 ');//Set VALUE=-SEL3 project is currently selected $ ("< Option value= ' 1 ' >1111</option><option value= ' 2 ' >2222</option> '). Appendto ("#sel")// Add option $ ("#sel") to the Drop-down box. Empty ()/clear dropdown box