JQuery gets the selected Text and Value of Select:
Copy codeThe Code is as follows:
Var checkText = jQuery ("# select_id"). find ("option: selected"). text (); // obtain the selected Text
Var checkValue = jQuery ("# select_id"). val (); // obtain the option Value selected by Select
Var checkIndex = jQuery ("# select_id"). get (0). selectedIndex; // obtain the index value selected by Select
Var maxIndex = jQuery ("# select_id option: last"). attr ("index"); // obtain the largest index value of Select
JQuery adds/deletes Select Option items:
Copy codeThe Code is as follows:
JQuery ("# select_id"). append ("<option value = 'value'> Text </option>"); // append an Option to Select (drop-down)
JQuery ("# select_id"). prepend ("<option value = '0'> Select </option>"); // insert an Option for Select (first position)
JQuery ("# select_id option: last"). remove (); // Delete the maximum Option of the index value in Select (last)
JQuery ("# select_id option [index = '0']"). remove (); // Delete the Option with the index value 0 in Select (the first option)
JQuery ("# select_id option [value = '3']"). remove (); // Delete the Option of '3' in Select
JQuery ("# select_id option [text = '4']"). remove (); // Delete the Option of '4' Text = '4' in Select
Clear content:
Copy codeThe Code is as follows:
JQuery ("# select_id"). empty ();