Today I met a thief with a broken egg:
1. I click events from a drop-down list select to get the value of the options
Copy Code code as follows:
var product_id = $ (this). Val ()
Console.log out is found to be a number of groups, such as: ["51"]
And then make the following judgments
Copy Code code as follows:
Console.log (product_id);
if (product_id = = ' Wuyi ') {alert (111);}
if (product_id[0] = = ' Wuyi ') {alert (222);}
Found can be pop-up balloon, ni Ma This is not a hole in me?
2, I use this product_id to match whether or not to be included in an array
Error code:
Copy Code code as follows:
var result = $.inarray (product_id,arr_product_ids);
Correct code:
Copy Code code as follows:
var result = $.inarray (product_id[0],arr_product_ids);
$.inarray () must use product_id[0], that is, cannot use an array
It is not until today that the Drop-down list gets the value of the number group, with a deeper understanding of the great God, to explain.