jquery Gets the text and value selected by select:
Copy Code code as follows:
$ ("#select_id"). Change (function () {//code ...}); Adds an event for a select that fires when one of the items is selected
var checktext=$ ("#select_id"). Find ("option:selected"). Text (); Gets the text selected by select
var checkvalue=$ ("#select_id"). Val (); Gets the value of the Select selection
var checkindex=$ ("#select_id"). Get (0). SelectedIndex; Get the index value selected by select
var maxindex=$ ("#select_id option:last"). attr ("index"); Get the maximum index value for select
jquery Add/Remove option items for select:
Copy Code code as follows:
$ ("#select_id"). Append ("<option value= ' value ' >Text</option>"); Append an option to select (dropdown)
$ ("#select_id"). Prepend ("<option value= ' 0 ' > Please select </option>"); Inserts an option for the Select (first position)
$ ("#select_id option:last"). Remove (); Delete index value maximum option (last) in select
$ ("#select_id option[index= ' 0 ']"). Remove (); Delete option with index value of 0 in select (first)
$ ("#select_id option[value= ' 3 ']"). Remove (); Delete option value= ' 3 ' in select
$ ("#select_id option[text= ' 4 ']"). Remove (); Delete option text= ' 4 ' in select
Empty content:
Copy Code code as follows:
$ ("#charCity"). empty ();