Every time you operate a select, you always have to go out and look up the information. Why not summarize it yourself and just look here in the future.
For example
1. Select the item with value set to pxx
$(".selector").val("pxx");
2. Select the item that sets text to pxx
$(".selector").find("option[text='pxx']").attr("selected",true);
Here is a usage of square brackets. The equal sign in the square brackets is preceded by the attribute name without quotation marks. Many times, the use of square brackets can make logic very simple.
3. Get the value of the currently selected item
$(".selector").val();
4. Get the text of the currently selected item
$(".selector").find("option:selected").text();
Colon is used here. Mastering its usage and drawing inferences will also make the code simpler.
The cascade of selects is often used, that is, the value of the second select changes with the value selected by the first select. This is very simple in jquery.
For example:
// Clear the second one first
$(".selector2").empty();
// In actual applications, multiple options here are generally generated using loops
var option = $("
$(".selector2").append(option);
});