This article mainly introduces the jquery drop-down select control operation method sharing (jquery operation select). For more information, see
JQuery's method of obtaining and setting Select Options is summarized as follows: Code: $ ("# select_id "). change (function () {// code ...}); // Add an event for Select. When one of the Select events is selected, var checkText =$ ("# select_id") is triggered "). find ("option: selected "). text (); // obtain the Textvar checkValue selected by Select = $ ("# select_id "). val (); // obtain the Valuevar checkIndex selected by Select = $ ("# select_id "). get (0 ). selectedIndex; // obtain the selected index value var maxIndex =$ ("# select_id option: last "). attr ("index"); // obtain the maximum index value of Select $ ("# select_id "). get (0 ). selectedIndex = 1; // Select $ ("# select_id") for items whose Select index value is 1 "). val (4); // Select a Value of 4 from Select $ ("# select_id option [text = 'jquery ']"). attr ("selected", true); // set the Select Text value to jQuery and select the selected text. The Code is as follows: $ ("# ddlRegType "). find ("option: selected "). text (); obtain the value selected by the select statement. The Code is as follows: $ ("# nowamagic "). val (); obtain the index selected by the select statement. The Code is as follows: $ ("# nowamagic "). get (0 ). selectedIndex; Set select jQuery to add/delete Select Option items: the 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 maximum Option (last) of the index values in the Select statement $ ("# select_id option [index = '0']"). remove (); // delete Option (first) with the index value 0 in Select $ ("# select_id option [value = '3']"). remove (); // delete Option $ ("# select_id option [text = '4']") of Value = '3' in Select. remove (); // Delete the Select Option set '4' in the select statement. The Code is as follows: // index is the index value $ ("# nowamagic "). get (0 ). selectedIndex = index; set the value selected by select: the code is as follows: $ ("# nowamagic "). attr ("value", "Normal"); $ ("# nowamagic "). val ("Normal"); $ ("# nowamagic "). get (0 ). value = value; select the selected text: the code is as follows: var count = $ ("# nowamagicoption "). length; for (var I = 0; I <count; I ++) {if ($ ("# nowamagic "). get (0 ). options [I]. text = text) {$ ("# nowamagic "). get (0 ). options [I]. selected = true; break;} Clear select: the code is as follows: $ ("# nowamagic "). empty ();