jquery Gets the text and value selected by select:
Choose a Try
Syntax Explanation:
Copy Code code as follows:
. $ ("#select_id"). Change (function () {//code ...}); Adds an event for a select that fires when one of the items is selected
. var checktext=$ ("#select_id"). Find ("option:selected"). Text (); Gets the text selected by select
. var checkvalue=$ ("#select_id"). Val (); Gets the value of the Select selection
. var checkindex=$ ("#select_id"). Get (0). SelectedIndex; Get the index value selected by select
. var maxindex=$ ("#select_id option:last"). attr ("index"); Get the maximum index value for select
jquery Sets the Select selected text and value:
Syntax Explanation:
Copy Code code as follows:
. $ ("#select_id"). Get (0). selectedindex=1; Set item with select Index value 1 selected
. $ ("#select_id"). Val (4); Select to set the value of 4 for the Select
. $ ("#select_id option[text= ' jQuery ']"). attr ("selected", true); Set the text value of select to the item selected for jquery
jquery Add/Remove option items for select:
Click once, select to append an option
Click to insert an option in the first position of select
Click to delete Maximum index value option in select (Last one)
Syntax Explanation:
Copy Code code as follows:
. $ ("#select_id"). Append ("<option value= ' value ' >text</option > "); Appends an option (Drop-down)
. $ ("#select_id") to select. Prepend ("<option value= ' 0 ' > Please select </option>"); Inserts an option (the first position) for the Select
. $ ("#select_id option:last"). Remove ();//delete maximum index value option in select (last)
. $ ("#select_ ID option[index= ' 0 '] ". Remove (); Delete option (first)
. $ ("#select_id option[value= ' 3 ']" in select with index value of 0. Remove ();//delete option value= ' 3 ' in select
. $ (" #select_id option[text= ' 4] "). Remove (); Delete option
for text= ' 4 ' in select