//traverse option and Add, remove optionfunctionChangeshipmethod (shipping) {varLen = $ ("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]")); } } //Gets the selected value of the drop-down menu$ (#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 (); Span style= "COLOR: #008000" >// Gets 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 (); // Gets 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 of the drop-down menu $ ("#select"). empty (); // $ ("<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 (); // //
3, check box:
$ ("input[@type =checkbox][@checked]"). each (function//alert ($ ( This ). Val ()); }); $ ("#chk1"). attr ("Checked", "'); // $ ("#chk2"). attr ("Checked",true); // If//
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 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", ' 11 ');//Populating contentMultiple marquee checkbox: $ ("#chk1"). attr ("Checked", "");//no tick .$ ("#chk2"). attr ("Checked",true);//Tick if($ ("#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 box select: $ ("#sel"). attr ("value", '-sel3 ');//set the VALUE=-SEL3 item as the currently selected item$ ("<optionvalue= ' 1 ' >1111</option><optionvalue= ' 2 ' > 2222</option>"). AppendTo ("#sel")//option to add a drop-down box$ ("#sel"). empty ();//empty drop-down boxgets the value of a set of radio selected itemsvarItem = $ (' 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", ' 11 ');//Populating contentMultiple 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 box select: $ ("#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 control drop-down list