我在js中有一个数组,希望用户检查其产品编号是否存在于数组中。代码是:
var arr = ['3bktzgo4','2ltold4k','l4u93l4r'];
function check() {
var input = document.getElementById("Input").value;
for (i = 0; i < arr.length; i++) {
if (arr[i] == input) {
alert("congratulations! Product code found! Your product is original!");
return;
}
}
alert("Product code not found! Your product is counterfeit!");
};
<div>
<button onclick="beginhere()">Search</button>
<input id='Input'>
</div>