JQuery gets the selected Text and Value of Select:
Syntax explanation:
1. $ ("# select_id"). change (function () {// code...}); // Add an event for Select, triggered when one of the Select events is selected
2. var checkText = $ ("# select_id"). find ("option: selected"). text (); // obtain the selected Text
3. var checkValue = $ ("# select_id"). val (); // obtain the Value selected by Select
4. var checkIndex = $ ("# select_id"). get (0). selectedIndex; // obtain the index value selected by Select
5. var maxIndex = $ ("# select_id option: last"). attr ("index"); // obtain the largest index value of Select.
JQuery sets the Text and Value selected by Select:
Syntax explanation:
1. $ ("# select_id"). get (0). selectedIndex = 1; // Select an item whose Select index value is 1
2. $ ("# select_id"). val (4); // Select an item whose Value is set to 4.
3. $ ("# select_id option [text = 'jquery ']"). attr ("selected", true); // set the Select Text value to jQuery.
JQuery adds/deletes Select Option items:
Syntax explanation:
1. $ ("# select_id"). append ("<option value = 'value'> Text </option>"); // append an Option for Select (drop-down)
2. $ ("# select_id "). prepend ("<option value = '0'> Select </option>"); // insert an Option for Select (first position)
3. $ ("# select_id option: last"). remove (); // Delete the largest Option (last) index value in Select)
4. $ ("# select_id option [index = '0']"). remove (); // Delete the Option with the index value 0 in Select (the first option)
5. $ ("# select_id option [value = '3']"). remove (); // Delete the Option with Value = '3' In the Select statement
6. $ ("# select_id option [text = '4']"). remove (); // Delete the Option of '4' Text = '4' in Select