Get the value of the drop-down list box is an array, and then use product_id to match whether it is contained in an array. If you are interested, do not miss the problem of a zombie today:
1. I click an event from a drop-down list to obtain the value of options.
The Code is as follows:
Var product_id = $ (this). val ()
Console. log is an array, for example, ["51"]
Then I made the following judgment:
The Code is as follows:
Console. log (product_id );
If (product_id = '51') {alert (111 );}
If (product_id [0] = '51') {alert (222 );}
The prompt box is displayed. Isn't Nima a pitfall for me?
2. I use this product_id to match whether it is contained in an array.
Error code:
The Code is as follows:
Var result = $. inArray (product_id, arr_product_ids );
Correct code:
The Code is as follows:
Var result = $. inArray (product_id [0], arr_product_ids );
$. InArray () must use product_id [0], that is, arrays are not allowed.
The value obtained from the drop-down list is an array. Please explain it.