Jquery operation drop-down list box implementation code

Source: Internet
Author: User

<Select name = "select1" id = "select1" size = "10">
<Option value = "1"> option1 </option>
<Option valeu = "2"> option2 </option>
<Option value = "3"> option3 </option>
<Option value = "4"> option4 </option>
</SELECT>

1. Get the jquery object
OBJ = $ ('# select1 ');

2. Get the length of options
Len = $ ('# select1 option'). Length

3. Traverse Option
For (VAR I = 0; I <Len; I ++ ){
Option_value = OBJ [0]. Options [I]. value;
Option_text = OBJ [0]. Options [I]. text;
}

4. Obtain the selected value
Obj_value = $ ('# select1'). Val ();

5. Get the text corresponding to the selected value
Obj_text = OBJ [0]. Options [OBJ [0]. selectedindex]. text;

6. Add an option
OBJ. append ('<option value = "5"> option5 </option> ');

7. delete an option
$ ('# Select1 option [value = "1"]'). Remove ();

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.