I encountered a broken problem today:
1. I clicked the event from a drop-down list select to get the value of options
var product_id = $(this).val()
When the console.log comes out, it is found to be an array. , such as: ["51"]
Then make the following judgment
console.log(product_id);
if(product_id == '51'){alert(111);}
if(product_id[0] == '51'){alert (222);}
I found that a prompt box can pop up, isn’t this a trick on me?
2. I use this product_id to match whether it is included in an array
Error code:
var result = $. inArray(product_id,arr_product_ids);
Correct code:
var result = $.inArray(product_id[0],arr_product_ids);
$.inArray() must use product_id[0], which means that arrays cannot be used
I didn’t know until today that the value obtained by the drop-down list is an array. If someone knows more about it, please explain.
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn