jquery Get and set select options Common Methods Summary

Source: Internet
Author: User

1. Get the text selected by select:
$ ("#cusChildTypeId"). Find ("option:selected"). Text ();
$ ("#cusChildTypeId option:selected"). Text ()
2. Get the value selected by select:
$ ("#ddlRegType"). Val ();
3. Get the selected index for select:
$ ("#ddlRegType"). Get (0). SelectedIndex;
4. Get the number of select items
$ ("#cusChildTypeId"). Get (0). options.length
5. Set the index selected by select:
$ ("#cusChildTypeId"). Get (0). Selectedindex=index;//index as index value
6. Set the value selected by select:
$ ("#cusChildTypeId"). attr ("value", "Normal");
$ ("#cusChildTypeId"). Val ("Normal");
$ ("#cusChildTypeId"). Get (0). Value = "Normal";
7. Set the text selected by select:
1>.var count=$ ("#cusChildTypeId"). Get (0). Options.length;
for (Var i=0;i<count;i++)
{
if ($ ("#cusChildTypeId"). Get (0). Options.text = = text)
{
$ ("#cusChildTypeId"). Get (0). options.selected = true;
Break
}
}

2>.$ ("#cusChildTypeId"). val (text);
$ ("#cusChildTypeId"). Change ();
8. Add an entry to the select that displays text with a value of
$ ("#cusChildTypeId"). Get (0). Options.add (New Option (Text,value));
9. Delete the item with value in select
var count = $ ("#cusChildTypeId"). Size ();
for (Var i=0;i<count;i++)
{
if ($ ("#cusChildTypeId"). Get (0). Options[i].value = = value)
{
$ ("#cusChildTypeId"). Get (0). remove (i);
Break
}
}
10. Clear the Select:
1>. $ ("#cusChildTypeId"). empty ();
2>. $ ("#cusChildTypeId"). Get (0). options.length = 0;

jquery Get and set select options Common Methods Summary

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.