Jsp jquery implements cascade menus, jquery's simple operations on select elements

Source: Internet
Author: User

The methods used to trigger the select event include click () and change ()
Click (): triggered only when the object is clicked.
Change (): triggered when the object changes
Below is a simple record of jquery's common operations on select:
1. Obtain the selected text in the select statement:
Js Code
$ ("# Id"). find ("option: selected"). text ();


2. Obtain the selected value of select:
Js Code
$ ("# Id"). val ();


3. Obtain the selected index of the select statement:
Js Code
$ ("# Id"). get (0). selectedindex;


4. Set the index selected by the select statement:
Js Code
$ ("# Id"). get (0). selectedIndex = 1; // note that I uppercase


5. Set the value selected by select:
Js Code
$ ("# Id"). attr ("value", "normal");
$ ("# Id"). val ("normal ");
$ ("# Id"). get (0). value = value;


6. Set select selected text:
Js Code
Var count = $ ("# ddlregtype option"). length;
For (var I = 0; I <count; I ++)
{If ($ ("# ddlregtype"). get (0). options [I]. text = text)
{
$ ("# Ddlregtype"). get (0). options [I]. selected = true;
Break;
}
}


7. Set select option items:
Js Code
$ ("# Select_id"). append ("<option value = 'value'> text </option>"); // Add an option
$ ("# Select_id"). prepend ("<option value = '0'> select </option>"); // insert an option
$ ("# Select_id option: last"). remove (); // Delete the option with the largest index value
$ ("# Select_id option [index = '0']"). remove (); // delete an option with an index value of 0
$ ("# Select_id option [value = '3']"). remove (); // delete an option with a value of 3
$ ("# Select_id option [text = '4']"). remove (); // delete an option with a text value of 4

 

This article is from "Life is like a play"
 

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.