The data that is usually obtained from the database requires the dropdown box text and value to be converted to each other
I've introduced a corresponding article earlier.
jquery Select to find text by value
This time, in turn, the jquery Select dropdown box uses text to find value
Find ways to try, and finally feel the most reliable use of cyclic option
Unless <option value= "0" text= "all" > All </option>
This is written in
$ ("#orderstate option[text= ' All ']"). Val ();
Look at the HTML
<th> Work order status:</th>
<td>
<select id= "orderstate" class= "select" style= "width:108px" >
<option value= "-1" > All </option>
<option value= "0" > Not audited </option>
<option Value= "1" > Unfinished </option>
<option value= "2" > has been completed </option>
</select>
</td >
So it doesn't make sense to use the above method, you can't find the value
The following loop is used to fix
var ordersate = $ ("#orderstate option[text= '" + state + "']"). Val ();
The jquery Select dropdown box uses text to find the value
function selectvalue (obj, text) {
var val = "";
$ ("#orderstate option"). each (the function () {
if ($ (this). Text () = = text) {
val = $ (This) . val ();
return false;
}
});
return Val;
}