jQuery get Text and Value Select choice:
code show as below:
$ ( "# select_id") change (function () {// code ...});. // add an event to Select, select one when the trigger
var checkText = $ ( "# select_id ") find (. "option: selected") text ( ); // get selected select text.
var CheckValue = $ ( "# select_id") Val (); // Gets Value select choice.
var checkIndex = $ ( "# select_id") .get (0) .selectedIndex; // get the index value selected select
var maxIndex = $. ( "# select_id option: last") attr ( "index"); // select obtain maximum index value
var checkText = $ ( "# select_id ") find (. "option: selected") text ( ); // get selected select text.
var CheckValue = $ ( "# select_id") Val (); // Gets Value select choice.
var checkIndex = $ ( "# select_id") .get (0) .selectedIndex; // get the index value selected select
var maxIndex = $. ( "# select_id option: last") attr ( "index"); // select obtain maximum index value
jQuery add / delete Select the Option key:
$ ( "# select_id") append ( "<option value = 'Value'> Text </ option>");. // append to a Select Option (dropdown)
. $ ( "# select_id") The prepend ( "< option value = '0'> select </ option> "); // insert a Option (first position) of select
$ (" # select_id Option: Last ") remove (); // delete select index. the maximum value Option (last)
$ ( "# select_id Option [index = '0']") remove ();. // delete the index value Select Option 0 (first)
$ ( "# select_id Option [ value = '3'] ") remove ();. // delete Select the value = '3' of the Option-
$ (" # select_id Option [text = '. 4'] ") remove ();. // delete Select the Text = '4' of Option
$ ( "# select_id") append ( "<option value = 'Value'> Text </ option>");. // append to a Select Option (dropdown)
. $ ( "# select_id") The prepend ( "< option value = '0'> select </ option> "); // insert a Option (first position) of select
$ (" # select_id Option: Last ") remove (); // delete select index. the maximum value Option (last)
$ ( "# select_id Option [index = '0']") remove ();. // delete the index value Select Option 0 (first)
$ ( "# select_id Option [ value = '3'] ") remove ();. // delete Select the value = '3' of the Option-
$ (" # select_id Option [text = '. 4'] ") remove ();. // delete Select the Text = '4' of Option
Empty the contents:
$("#charCity").empty();