JQuery gets the selected Text and Value of Select:
Select one. Try again.
Syntax explanation:
Copy codeThe Code is as follows:
. $ ("# Select_id"). change (function () {// code...}); // Add an event for Select, triggered when one of the Select events is selected
. Var checkText = $ ("# select_id"). find ("option: selected"). text (); // obtain the selected Text
. Var checkValue = $ ("# select_id"). val (); // obtain the Value selected by Select
. Var checkIndex = $ ("# select_id"). get (0). selectedIndex; // obtain the index value selected by Select
. 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:
Copy codeThe Code is as follows:
. $ ("# Select_id"). get (0). selectedIndex = 1; // Select an item whose Select index value is 1.
. $ ("# Select_id"). val (4); // Select an item whose Value is set to 4.
. $ ("# Select_id option [text = 'jquery ']"). attr ("selected", true); // Select an item whose Select Text value is set to jQuery
JQuery adds/deletes Select Option items:
Click once and Select will append an Option
Click to insert an Option at the first position of Select.
Click to delete the largest Option (the last one) of the index values in the Select statement)
Syntax explanation:
Copy codeThe Code is as follows:
. $ ("# Select_id"). append ("<option value = 'value'> Text </option>"); // append an Option for Select (drop-down)
. $ ("# Select_id "). prepend ("<option value = '0'> Select </option>"); // insert an Option for Select (first position)
. $ ("# Select_id option: last"). remove (); // Delete the largest Option (last) index value in Select)
. $ ("# Select_id option [index = '0']"). remove (); // Delete the Option with the index value 0 in Select (the first option)
. $ ("# Select_id option [value = '3']"). remove (); // Delete the Option of '3' in Select.
. $ ("# Select_id option [text = '4']"). remove (); // Delete the Option of '4' Text = '4' in Select.