jquery obtains the value of option and operates on option http://www.jb51.net/article/44443.htm
jquery Gets the Select element and selects the text and value:
jquery Gets the Select element and sets the text and value: Instance analysis: Copy the Code code as follows: $ ("#select_id"). Get (0). selectedindex=1; Set the Select index value to 1 to select $ ("#select_id"). Val (4); Set the value of the select value to 4 to select $ ("#select_id option[text= ' jQuery ']"). attr ("selected", true); Set the text value of the Select for jquery to select jquery Add/Remove option item for SELECT element: Instance Analysis: $ ("#select_id"). Append ("<option value= ' value ' >Text</option> "); Append an option (drop-down) $ ("#select_id") for select. Prepend ("<option value= ' 0 ' > Please select </option>"); Insert an option (first position) $ ("#select_id option:last") for Select. Remove (); Delete the index value in select maximum option (last) $ ("#select_id option[index= ' 0 ']"). Remove (); Delete option (first) $ ("#select_id option[value= ' 3 ')" with index value 0 in select. Remove (); Delete the option$ ("#select_id option[text= ' 4") of value= ' 3 ' in select. Remove (); Delete option three level classification for text= ' 4 ' in select <select name= "Thirdlevel" id= "Thirdlevel" onchange= "Getfourthlevel ()" >< Option value= "0" id= "thirdoption" > Please select Category three </option></select></div> class four: <select name= " Fourthlevelid "id=" Fourthlevelid "><option value="0 "id=" fourthoption "> Please select Level Four classification </option></select></div>if ($ (" #thirdLevel "). Val ()!=0) {$ (" # Thirdlevel option[value!=0]). Remove (); if ($ ("#fourthLevelId"). Val ()!=0) {$ ("#fourthLevelId option[value!=0]"). Remove (); This means: if we want to select the third class when choosing: if there is data in class fourth, delete if there is no data in class Fourth of the commodity as the default value. After learning Ajax technology in the back, often use! Get select: Gets the Select selected text: $ ("#ddlRegType"). Find ("option:selected"). Text (); Gets the value:$ selected by select ("#ddlRegType"). val (); Gets the index selected by select: $ ("#ddlRegType"). Get (0). SelectedIndex; Set Select: Sets the index selected by select: $ ("#ddlRegType"). Get (0). Selectedindex=index;//index Set the Select selected Value:$ ("#ddlRegType") for the index value. attr ("value", "Normal"); $ ("#ddlRegType"). Val (" Normal "), $ (" #ddlRegType "). Get (0). value = value; Set 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 Select option entry: $ ("#select_id"). Append ("<option ValUe= ' Value ' >Text</option> '); Add a option$ ("#select_id"). Prepend ("<option value= ' 0 ' > Please select </option>"); Insert a option$ ("#select_id option:last") in front. Remove (); Delete the option$ with the largest index value ("#select_id option[index= ' 0"). Remove ();//delete the option$ with an index value of 0 ("#select_id option[value= ' 3 ']"). Remove (); Remove option$ ("#select_id option[text= ' 4") with a value of 3. Remove (); Delete the text value of 4 option to empty the select:$ ("#ddlRegType"). empty (); jquery Gets the value: Val () text () sets the value Val (' Set value here ') $ ("document"). Ready ( Function () {$ ("#btn1"). Click (function () {$ ("[name= ' checkbox ']"). attr ("Checked", ' true '),//Select All}) $ ("#btn2"). Click ( Function () {$ ("[name= ' checkbox ']"). Removeattr ("checked");//Deselect All}) $ ("#btn3"). Click (function () {$ ("[Name= ' checkbox ']:even '). attr ("Checked", ' true ');//Select All Odd}) $ ("#btn4"). Click (function () {$ ("[name= ' checkbox ']"). each (function () { Reverse Select if ($ (this). attr ("checked")) {$ (this). Removeattr ("checked"); else{$ (This). attr ("Checked", ' true ');})}) $ ("#btn5"). Click (function () {//Output selected value var str= ""; $ ("[name= ' checkbox '][checked]"). each (function () {str+=$ (this).Val () + "\ r \ n";//alert ($ (this). Val ());}) alert (str);})})
jquery Gets the value of option and operates on option