jquery settings Gets the value of the drop-down menu option multiple instances

Source: Internet
Author: User

Share the next jquery how to set the Get drop-down menu for an option value, a variety of methods, worth collecting.

jquery Get and set select options

Get select:
Gets the text selected by the Select:
$ ("#ddlRegType"). Find ("option:selected"). Text ();
Gets the value selected by select:
$ ("#ddlRegType"). Val ();
Gets the index selected by the Select:
$ ("#ddlRegType"). Get (0). SelectedIndex;
Set Select:
To set the index selected by select:
$ ("#ddlRegType"). Get (0). Selectedindex=index;//index sets the value of select selected for index values
:
$ ("#ddlRegType"). attr ("value", "Normal");
$ ("#ddlRegType"). Val ("Normal");
$ ("#ddlRegType"). Get (0). value = value;
Set Select selected text:
var count=$ ("#ddlRegType option"). Length;
for (Var i=0;i<count;i++)
{if ($ ("#ddlRegType"). Get (0). Options[i].text = = text)
{//www.jbxue.com
$ ("# Ddlregtype "). Get (0). options[i].selected = true;
break;
}
}
Empty Select:
$ ("#ddlRegType"). empty ();

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.