gets select: Gets the Select selected text: $ ("#ddlRegType"). Find ("option:selected")). text (); Gets the value selected by select: $ ("#ddlRegType"). Val (); Gets the selected index of select: $ ("#ddlRegType"). Get (0). SelectedIndex; Set Select: Sets the index selected by select: $ ("#ddlRegType"). Get (0). Selectedindex=index;//index is the indexed valueSet Select to select the value: $ ("#ddlRegType"). attr ("Value", "Normal "); $("#ddlRegType"). Val ("Normal")); $("#ddlRegType"). Get (0). value = value; Set the Select Selected Text:var count=$ ("#ddlRegType option"). length; for (Var i=0;i<count;i++) {if ($ ("#ddlRegType"). Get (0). Options[i].text = = text) {$ ("#ddlRegType"). Get (0). options[i].selected = true; Break } } $("#select_id option[text= ' jQuery ']"). attr ("Selected", True); Set the Select option entry: $ ("#select_id"). Append ("<option value= ' value ' >Text</option>"); Add an option$("#select_id"). Prepend ("<option value= ' 0 ' > Please select </option>");//Insert an option in front$("#select_id option:last"). Remove ();//Remove the most indexed value option$("#select_id option[index= ' 0 ']"). Remove ();//Delete option with index value 0$("#select_id option[value= ' 3 ']"). Remove ();//Delete option with a value of 3$("#select_id option[text= ' 4 ']"). Remove ();//Delete option with a text value of 4Empty select:$ ("#ddlRegType"). empty (); jquery Gets the value:. val (). Text () Setting value. val (' Set the value here ') $("Document"). Ready (function(){ $("#btn1"). Click (function(){ $("[Name= ' checkbox ']"). attr ("Checked", ' true ');//Select All}) $("#btn2"). Click (function(){ $("[Name= ' checkbox ']"). Removeattr ("checked");//Cancel Select all}) $("#btn3"). Click (function(){ $([name= ' checkbox ']:even '). attr ("Checked", ' true ');//Check all odd}) $("#btn4"). Click (function(){ $("[Name= ' checkbox ']"). each (function(){//Inverse Selectionif($( This). attr ("Checked")){ $( This). Removeattr ("Checked"); } Else{ $( This). attr ("Checked", ' true '); } }) }) $("#btn5"). Click (function(){//Output the selected valuevarStr= ""; $("[name= ' checkbox '][checked]"). each (function() {str+=$( This). Val () + "\ r \ n"; //alert (This). Val ());}) alert (str); }) })
Original address: http://www.cnblogs.com/summer_adai/archive/2012/12/01/2797145.html
jquery obtains the value of select option and the action "transfer" to select option