JQuery obtains the Text and Value selected by the Select statement and adds and deletes the Option items of the Select statement. This article describes the specific implementation in detail, if you are interested, you can refer to jQuery to obtain the Text and Value selected by the Select statement:
The Code is as follows:
$ ("# Select_id"). change (function () {// code...}); // adds an event for Select, which is triggered when one of the selected 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 adds/deletes Select Option items:
The Code is as follows:
$ ("# Select_id"). append ("Text"); // Append an Option to Select (drop-down)
$ ("# Select_id"). prepend ("Select"); // 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 whose Value is '3' in Select.
$ ("# Select_id option [text = '4']"). remove (); // Delete the Option of '4' Text = '4' in Select.
Clear content:
The Code is as follows:
$ ("# CharCity"). empty ();