Every time the operation of the Select, always to come out to turn over the information, as a summary of their own, after the turn over here.
such as <select class= "selector" ></select>
1. Set value to Pxx item selected
$ (". Selector"). Val ("Pxx");
2. Set text to Pxx to select
$ (". Selector"). Find ("option[text= ' Pxx ')"). attr ("selected", true);
Here is the use of a bracket, preceded by the attribute name in parentheses, without quotation marks. In many cases, the use of brackets can make logic very simple.
3. Gets the value of the currently selected item
$ (". Selector"). Val ();
4. Gets the text of the currently selected item
$ (". Selector"). Find ("option:selected"). Text ();
Using a colon here, mastering its usage and extrapolate will also make the code concise.
There are many times when a select cascade is used, that is, the value of the second select changes with the value selected in the first select. This is very simple in jquery.
such as: $ (". Selector1"). Change (function () {
Clear the second one first.
$ (". Selector2"). empty ();
In real-world applications, the option here is typically generated by looping multiple
var option = $ ("<option>"). Val (1). Text ("Pxx");
$ (". Selector2"). Append (option);
});
jquery operation Select (value, set selected) [Go]