jquery action method for the text and value values of the Select drop-down box

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 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 sets the item with the index value of 1 as the currently selected item

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

5. jquery Set value 2 is the currently selected item

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

6. jquery set the text value to "Ivy 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 the end)

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

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

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

9. jquery Delete the last option of the Select drop-down box

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

Select Change value with OnChange method

<SelectID= "SELECTW"onchange= "Magchange ()">                       <optionvalue= "2"></option>                       <optionvalue= "1">Weibo</option>                   </Select>

Gets the value of the current selection when selected

function Magchange () {        var checkvalue=$ ("#selectw"). Val ();         return CheckValue;}

jquery action method for the text and value values of the Select drop-down box

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.