Reprint: http://www.cnblogs.com/pepcod/archive/2012/07/03/JavaScript.html
Query gets the text and value of the Select selection:
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 sets the text and value selected for select:
Determine if the item value= "Paravalue" exists in the Select option
function Jsselectisexititem (objselect) {varIsexit =false; for(vari =0; I < objselect.size (); i++) {if(Objselect[i].value = =5) {Isexit=true; Break;}}returnIsexit;} if(Jsselectisexititem (Objselect)) {//If there is a value=5 option, remove the$("#cardType option[value= ' 5 ']"). Remove (); }
Syntax Explanation:
1 $ ("#select_id"). Get (0). selectedindex=1; Set the Select index value to 1 to select 2 $ ("#select_id"). Val (4); Select 3 $ ("#select_id option[text= ' jQuery ') ' for the item with value 4 for select. attr (" selected ", true);
jquery Add/Remove option for select:
Syntax Explanation:
1 $ ("#select_id"). Append ("<option value= ' value ' >Text</option>"); Append an option (drop-down) of 2 $ ("#select_id") for select. Prepend ("<option value= ' 0 ' > Please select </option>"); Insert an option (first position) for select 3 $ ("#select_id option:last"). Remove (); Delete the index value in select maximum option (last) 4 $ ("#select_id option[index= ' 0 ']"). Remove (); Delete option with index value 0 in select (first) 5 $ ("#select_id option[value= ' 3 ']"). Remove (); Delete Option6 $ ("#select_id option[text= ' 4") for value= ' 3 ' in select. Remove (); Delete option for text= ' 4 ' in select
jquery operates the Select option collection to determine whether the option is present in the collection