jquery operations a method for the text value and value of the Select Drop-down box _jquery

Source: Internet
Author: User
1. jquery Gets the text value of the currently selected select

var checktext=$ ("#slc1"). Find ("option:selected"). Text ();

2. jquery gets the value value of the currently selected select

var checkvalue=$ ("#slc1"). Val ();

3. jquery Gets the index value of the currently selected select

var index=$ ("#slc1"). Get (0). SelectedIndex;

4, jquery set an index value of 1 is the current selected item

$ ("#slc1"). Get (0). selectedindex=1;

5, jquery set the value of value 2 is the current selected item

$ ("#slc1"). Val (2);

6. jquery sets the item with the text value "Green rattan garden" as the current selected item

$ ("#slc1 option[text= ' green garden w ']"). attr ("selected", true);

7. Append an option to the specified select Drop-down box (append to end)

$ ("#slc2"). Append ("+i+");

8. Insert an option for the Select Drop-down box (insert to first position)

$ ("#slc2"). Prepend ("Please choose");

9. jquery Delete the last option in the Select Drop-down box

$ ("#slc2 option:last"). Remove ();

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.