jquery Operation dropdown Box (DropDownList) for value assignment

Source: Internet
Author: User

jquery Operation drop-down box (DropDownList) Presumably everyone has a touch, below to share with you the implementation of the DropDownList value Assignment code

1. Get the check:

Gets the value of the selected item: $ ( ' select#sel option:selected  ' " select#sel  " ' 


2. Gets the index value of the currently selected item:

$ (' Select#sel '). Get (0). SelectedIndex;


3. Get the maximum index value for the current option:

$ (' Select#sel option:last '). attr ("index")


4. Get the length of the DropDownList:

$ (' Select#sel ') [0].options.length;
Or
$ (' Select#sel '). Get (0). Options.length;


5. Set the first option to a selected value:

$ (' Select#sel option:first '). attr (' selected ', ' true ')
Or
$ (' Select#sel ') [0].selectedindex = 0;


6. Set the last option to the selected value:

$ (' Select#sel option:last). attr (' selected ', ' true ')


7. Set any option to the selected value according to the index value:

$ (' Select#sel ') [0].selectedindex = index value; index value =0,1,2 ....


8. Set option for Value=4 to the selected value:

$ (' Select#sel '). attr (' Value ', ' 4 ');
Or
$ ("Select#sel option[value= ' 4 ']"). attr (' selected ', ' true ');


9. Delete the value=3 option:

$ ("Select#sel option[value= ' 3 ']"). Remove ();


10. Delete the first few option:

$ ("Select#sel option"). EQ (index value). Remove (); index value =0,1,2 ....
If you delete a 3rd radio:
$ ("Select#sel option"). EQ (2). Remove ();


11. Delete the first option:

$ ("Select#sel option"). EQ (0). Remove ();
Or
$ ("Select#sel Option:first"). Remove ();


12. Delete the last option:

$ ("Select#sel option:last"). Remove ();


13. Delete DropDownList:

$ ("Select#sel"). Remove ();


14. Add an option after the select:

$ ("Select#sel"). Append ("F");


15. Add an option in front of select:

$ ("Select#sel"). Prepend ("0");


16. Traverse option:

$ (' select#sel option '). each (function (index, domele) {
Write code
});

Original: http://www.jb51.net/article/40545.htm

jquery Operation dropdown Box (DropDownList) for value assignment

Related Article

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.