JQ operation of the HTML select control

Source: Internet
Author: User

JQ operation of the HTML select control

1. Determine if the value= "Paravalue" item exists in the SELECT option
$ ("#selectid option[@value = ' paravalue ']"). length>0
2. Add an item to the Select option
$ ("#selectid"). Append ("<option value=" >1111<option> ");
3. Remove an item from the Select option
$ ("#selectid"). Remove ("<option value= >1111<option>");
4. Modify the text of value= "Paravalue" in the Select option to "Paratext"
$ ("#selectid option:selected"). attr ("value", "Paravalue"). attr ("text", "Paratext");
5. Set the first item of text= "Paratext" in Select to be selected
$ ("#selectid option[@text = ' paratext ']"). attr ("Selected", "true")
6. Set the item of value= "Paravalue" in Select to select
$ ("#selectid option[@value = ' paravalue ']"). attr ("Selected", "true")

7. Set the first item in select to select
$ ("#selectid option"). EQ (0). attr (' selected ', ' true ');

8. Gets the value of the current selected item of select
$ ("#selectid"). Val ();
9. Gets the text of the current selected item of select
$ ("#selectid"). Text ();
10. Get the index of the current selected item of select
document.getElementById ("Select1"). SelectedIndex;
$ ("#selectid"). Get (0). SelectedIndex
11. Clear the Select item
$ ("#selectid"). empty ();

Note: the EQ () method

The EQ () method assigns a matching element set reduction value to one on index.

$ (' li '). EQ (2). CSS (' background-color ', ' red ');    

The result of this call is that the red background is set for Item 3. Note that index is zero-based and is the location of the reference element in the JQuery object, not in the DOM tree.

JQ operation of the HTML select control

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.