JQuery operations on Select large collection of favorites

  • 2020-03-30 01:09:51
  • OfStack

1. Add/remove options of Select in jQuery:
2. $(" # select_id "). Append (" < The option value = 'value' > Text< / option>" );     // appends an Option(drop-down item)  to Select;
3. $(" # select_id "). The prepend (" < The option value = '0' > Please select < / option>" );     // inserts an Option(first position) 
4. $(" # select_id option: last "). The remove ();     // deletes the largest Option(the last one) 
5. $(" # select_id option [index = '0'] "). The remove ();     // deletes Option(the first one) with index value of 0 in Select  
6. $(" # select_id option (value = '3'] "). The remove ();     // delete Option  Value='3' from Select;
7. $(" # select_id option [text = '4'] "). The remove ();     // delete Option  Text='4' from Select;
8. $(" # select_id "). The empty (); // clears the option in the select
 

1. JQuery gets the Text and Value of Select:
2. $(" # select_id "). Change (function () {/ / code... });       // adds an event to the Select, which is triggered when one of the items is selected
3. The var checkText = $(" # select_id "). The find (" option: selected "). The text ();     // gets the Text  Select;
4. Var checkValue = $(" # select_id "). Val ();     // gets Value  Select;
5. The var checkIndex = $(" # select_id "). The get (0). SelectedIndex;     // gets the index value of the Select selection
6. Var maxIndex = $(" # select_id option: last "). The attr (" index ");     JQuery set the Text and Value of Select Select:


Related articles: