JQuery's large set of Select operations (favorites)

Source: Internet
Author: User

1. jQuery adds/deletes Select Option items:
2. $ ("# select_id"). append ("<option value = 'value'> Text </option>"); // append an Option for Select (drop-down)
3. $ ("# select_id "). prepend ("<option value = '0'> Select </option>"); // insert an Option for Select (first position)
4. $ ("# select_id option: last"). remove (); // Delete the maximum Option of the index value in the Select statement (last one)
5. $ ("# select_id option [index = '0']"). remove (); // Delete the Option with the index value 0 in Select (the first option)
6. $ ("# select_id option [value = '3']"). remove (); // Delete the Option with Value = '3' In the Select statement
7. $ ("# select_id option [text = '4']"). remove (); // Delete the Option of '4' Text = '4' in Select
8. $ ("# select_id"). empty (); // clear the option
 

1. jQuery gets the Text and Value selected by the Select statement:
2. $ ("# select_id"). change (function () {// code...}); // Add an event for Select, triggered when one of the Select events is selected
3. var checkText = $ ("# select_id"). find ("option: selected"). text (); // obtain the selected Text
4. var checkValue = $ ("# select_id"). val (); // obtain the Value selected by Select
5. var checkIndex = $ ("# select_id"). get (0). selectedIndex; // obtain the index value selected by Select
6. var maxIndex = $ ("# select_id option: last"). attr ("index"); // obtain the largest index Value of Select. jQuery sets the Text and Value selected by Select:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.