Jquery select selection value assignment and jquery simulation select beautification code this tutorial mainly describes the jquery select selection value assignment and jquery simulation select beautification, a lot of talk, if you learn jquery, I want to beautify the select statement. This tutorial is for you. It is important to assign values to the query select statements.
Jquery select selection value assignment and jquery simulation select beautification code
This tutorial mainly describes how to assign values to selected values of jquery select and how to simulate select beautification by jquery. If you want to learn jquery, You Want To beautify select, in this tutorial, the assignment of the selected query select value is important.
Obtain the value of the first option.
$ ('# Test option: first'). val ();
// The value of the last option
$ ('# Test option: last'). val ();
// Obtain the value of the second option
$ ('# Test option: eq (1)'). val ();
// Obtain the selected value
$ ('# Test'). val ();
$ ('# Test option: selected'). val ();
// Option with the value of 2 is selected
$ ('# Test'). attr ('value', '2 ');
// Set the first option to selected
$ ('# Test option: last'). attr ('selected', 'selected ');
$ ("# Test"). attr ('value', $ ('# test option: la'). val ());
$ ("# Test "). attr ('value', $ ('# test option '). eq ($ ('# test option '). length-1 ). val ());
// Obtain the select Length
$ ('# Test option'). length;
// Add an option
$ ("# Test"). append ("<option value = '9'> ff </option> ");
$ ("<Option value = '9'> ff </option>"). appendto ("# test ");
// Add the selected item
$ ('# Test option: selected'). remove ();
// Select a specified item
$ ('# Test option: first'). remove ();
// The specified value is deleted.
$ ('# Test option'). each (function (){
If ($ (this). val () = '5 '){
$ (This). remove ();
}
});
$ ('# Test option [value = 5]'). remove (); 1 2 3 4 5 6