Http://ghl68754031.k15.wg8.com/
Jquery obtains the client control select
1. Obtain the value related to the selected text in the SELECT statement.
Obtain the selected text: var checktext = $ ("# slc1"). Find ("option: Selected"). Text ();
Obtain the value selected by select: var checkvalue = $ ("# slc1"). Val ();
Obtain the index value selected by select: var checkindex = $ ("# slc1"). Get (0). selectedindex;
Obtain the largest index value of select: var maxindex =$ ("# slc1 option: Last"). ATTR ("Index ");
Ii. set text and value selected by select
Select an item whose select index value is 1: $ ("# slc1"). Get (0). selectedindex = 1;
Select an item whose value is 4: $ ("# slc1"). Val (4 );
Set the select text value to jquery:
$ ("# Slc1 option [TEXT = 'jquery ']"). ATTR ("selected", true );
PS: pay special attention to the use of the third item. Look at jquery's selector feature so powerful!
3. add and delete option items
Append an option to select (drop-down)
$ ("# Slc2"). append ("<option value = '" + I + "'>" + I + "</option> ");
Insert an option for select (first position)
$ ("# Slc2"). prepend ("<option value = '0'> select </option> ");
PS: prepend this is the best way to insert content to the beginning of all matching elements.
Delete the maximum option (last one) of the index values in the SELECT statement)
$ ("# Slc2 option: Last"). Remove ();
Delete option (first) with index value 0 in select)
$ ("# Slc2 option [Index = '0']"). Remove ();
Delete option with value = '3' in select
$ ("# Slc2 option [value = '3']"). Remove ();
Delete the option of '4' text = '4' in the SELECT statement.
$ ("# Slc2 option [TEXT = '3']"). Remove ();