This article summarizes the selection of the text and value;jquery Add/Remove options option for jquery to get Select, and gives a corresponding explanation.
jquery Gets the text and value selected by select:
Syntax Explanation:
$ ("#select_id"). Change (function () {// code ...}); Adds an event for select, triggering var checktext=$ ("#select_id") when one of the items is selected. Find ("option: Selected "). Text (); // Gets the text of select selection var checkvalue=$ ("#select_id"). Val (); // var checkindex=$ ("#select_id"). Get (0). SelectedIndex; // Gets the index value of the select selection var maxindex=$ ("#select_id option:last"). attr ("index"); // Get Select maximum index value jquery setting select text and value:
Syntax Explanation:
$ ("#select_id"). Get (0). selectedindex=1; // Set the Select index value to 1 to select $ ("#select_id"). Val (4); // Sets the value of select to 4 for the item selected true); // set the text value of select to the item selected for jquery
jquery Add/Remove option for select:
Syntax Explanation:
$ ("#select_id"). Append ("<option value= ' value ' >Text</option>"); // append an option (drop-down) $ ("#select_id") for select. Prepend ("<option value= ' 0 ' > Please select </option> "); // insert an option (first position) $ ("#select_id option:last") for Select. Remove (); // $ (" #select_id option[index= ' 0 '] "). Remove (); // $ (" #select_id option[value= ' 3 ") of the index value 0 in select. Remove (); // remove option $ ("#select_id option[text= ' 4") in select Value= ' 3 '. Remove (); // for text= ' 4 ' in select
JQuery Select Operation Large Collection