Obtain Select:
Obtain the selected text in the select statement:
$ ("# DdlRegType"). find ("option: selected"). text ();
Obtain the value selected by the select statement:
$ ("# DdlRegType"). val ();
Obtain the index selected by the select statement:
$ ("# DdlRegType"). get (0). selectedIndex;
Set select:
Set the index selected by select:
$ ("# DdlRegType"). get (0). selectedIndex = index; // index indicates the index value.
Set the value selected by select:
Copy codeThe Code is as follows:
$ ("# DdlRegType"). attr ("value", "Normal");
$ ("# DdlRegType"). val ("Normal ");
$ ("# DdlRegType"). get (0). value = value;
Set select selected text:
Copy codeThe Code is as follows:
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;
}
}
$ ("# Select_id option [text = 'jquery ']"). attr ("selected", true );
Set select option items:
Copy codeThe Code is as follows:
$ ("# 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
Clear Select:
$ ("# DdlRegType"). empty ();