jquery Gets the text and value selected by select:
Syntax Explanation:
1. $ ("#select_id"). Change (function () {//code ...}); Adds an event for select, triggering 2 when one of the items is selected. var checktext=$ ("#select_id"). Find ("option:selected"). Text (); Gets the Text3 selected by the Select. var checkvalue=$ ("#select_id"). Val (); Gets the Value4 selected by the Select. var checkindex=$ ("#select_id"). Get (0). SelectedIndex; Gets the index value of the select selection of 5. var maxindex=$ ("#select_id option:last"). attr ("index"); Gets the maximum index value of the Select jquery setting select text and Value:
Syntax Explanation:
1. $ ("#select_id"). Get (0). selectedindex=1; Set the Select index value to 1 to select 2. $ ("#select_id"). Val (4); Set the value of select to 4 to select 3. $ ("#select_id option[text= ' jQuery ']"). attr ("selected", true); Set the text value of the Select for jquery to select jquery to add/Remove option items for select:
Syntax Explanation:
1. $ ("#select_id"). Append ("<optionvalue= ' Value '>Text</option>"); Append an option to the Select (drop-down) 2. $ ("#select_id"). Prepend ("<optionvalue= ' 0 '>Please select</option> "); Insert an option (first position) 3 for select. $ ("#select_id option:last"). Remove (); Delete the index value in select maximum option (last) 4. $ ("#select_id option[index= ' 0 ']"). Remove (); Delete option (first) 5 with index value 0 in select. $ ("#select_id option[value= ' 3 ']"). Remove (); Delete the Option5 of value= ' 3 ' in select. $ ("#select_id option[text= ' 4 ']"). Remove (); Delete Optionhttp://www.cnblogs.com/xinlinux/jquery radio value of text= ' 4 ' in Select, CheckBox value, select Value, Radio selected, checkbox selected , select selected, and its correlation gets a set of radio values for the selected item 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 a 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-marquee 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", "");//Empty contents $ ("#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)//Determine if the radio group has been ticked radio: $ ("Input[type=radio]"). attr ("Checked", ' 2 ');//Set value=2 items as the current Check drop-down box select: $ ("#sel"). attr ("value", '-sel3 ');//Set VALUE=-SEL3 item as the currently selected $ ("<optionvalue= ' 1 '>1111</option><optionvalue= ' 2 '>2222</option>"). AppendTo (" #sel ")//Add the option $ (" #sel ") to the drop-down box. 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 ($ (). val () = = 111) {$ (this). Remove ( );}});} else{$ ("<optionvalue= ' 111 '>UPS Ground</option>"). AppendTo ($ (" Select[name=ishiptype] "));}} Gets the selected value of the drop-down list $ (#testSelect option:selected '). Text (), or $ ("#testSelect"). Find (' option:selected '). Text (), or $ ("# Testselect "). Val (); 1, drop-down box: var cc1 = $ (". FORMC select[name= ' country '] option[selected] "). Text (); Get the text of the selected item in the drop-down menu (note that there are spaces in the middle) var CC2 = $ ('. FORMC select[name= "Country"]). Val (); Get the value of the selected item in the drop-down menu var cc3 = $ ('. FORMC select[name= "Country"]). attr ("id"); Gets the ID property value of the selected item in the drop-down menu ("#select"). empty ();//Empty the drop-down box//$ ("#select"). HTML ("); $ ("<optionvalue= ' 1 '>1111</option>"). AppendTo (" #select ")//Add a drop-down box option to explain a little bit: 1.select[name= ' country '] option[selected] means having the Name property, and the property value is ' Option element with selected attribute inside country ' select element; 2, Radio Box: $ ("input[@type =radio][@checked]"). Val (); Get the value of the selected item in the Radio box (note that there is no space 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 is no space in the middle) 3, check box: $ ("input[@type =checkbox][@checked]"). Val (); The value of the first item that gets the check box selected is $ ("input[@type =checkbox][@checked]"). each (function () {////Because the check box is generally selected for more than one, you can loop out the alert ($ (this). val ());}); $ ("#chk1"). attr ("checked");//Do not tick $ ("#chk2"). attr ("Checked", true);//Tick if ($ ("#chk1"). attr (' checked ') = = Undefined) {}//Determine if it has been ticked of course the jquery selector is powerful. There are many other ways.<Scriptsrc= "Jquery-1.2.1.js"type= "Text/javascript"></Script><Scriptlanguage= "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><ahref="#">Aaass</a><!--Drop- down box -<SelectID= "Selecttest"name= "Selecttest"><optionvalue= "1">11</option><optionvalue= "2">22</option><optionvalue= "3">33</option><optionvalue= "4">44</option><optionvalue= "5">55</option><optionvalue= "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 the value of the selected item var item = $ (' input[@name = items][@checked]). Val (); Gets the text of the Select selected item var item = $ ("select[@name =items] option[@selected]"). text (); select The second element of the 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; Gets the value: text box, text area: $ ("#txt"). attr ("value"), Multi-marquee 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", ");//Empty contents $ (" #txt "). attr ("Value", ' 11 ');//Fill Content Multi Box checkbox: $ ("#chk1"). attr ("Checked", "");//Do not tick $ ("#chk2"). attr ("Checked", true);//Tick if ($ ("#chk1"). attr (' checked ') ==undefined)//Determine if the radio Group radio: $ ("input[@type =radio]"). attr ("Checked", ' 2 ');// Set the value=2 item to the currently selected drop-down box for select: $ ("#sel"). attr ("value", '-sel3 ');//Set the VALUE=-SEL3 item as the currently selected $ ("<optionvalue= ' 1 ' >1111</option><optionvalue= ' 2 '>2222</option& gt; "). AppendTo ("#sel")//Add option$ ("#sel") to the drop-down box. empty ();//Empty drop-down box gets the value of a set of radio selected items 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 check 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"), Multi-marquee 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", "");//Empty contents $ ("#txt"). attr ("value", ' 11 ') ;//Fill in the Content Marquee checkbox: $ ("#chk1"). attr ("Checked", "");//Do not tick $ ("#chk2"). attr ("Checked", true);//Tick if ($ ("#chk1"). attr (' Checked ')//==undefined)//Determine if the radio group has been ticked radio: $ ("input[@type =radio]"). attr ("Checked", ' 2 ');//Set value=2 items as the current Check drop-down box Select: $ ("#sel"). attr ("value", '-sel3 ');//Set VALUE=-SEL3 item as currently selected $ ("<option value= ' 1 '>1111</option><optionvalue= ' 2 '>2222</option>"). AppendTo (" #sel ")//Add option$ (" #sel ") to the drop-down box. empty ();//Empty drop-down box