我有这个JS代码,我需要将输入值与数组进行比较,如果输入值与数组中的某个值匹配,则显示相关消息,但我无法获取数组值并将它们与我的输入值。
var invalidkeyreservation = ['ABCDEF','GHIJK','LMNOP'];
if ($("input.reservationkey").val() === invalidkeyreservation) {
BootstrapDialog.show(return $content;}
} else{
window.location.href = "/branches/Cancelaciones/Seleccion.html";
}
最佳答案
这就是 .indexOf()
是为了。
var invalidkeyreservation = ['ABCDEF','GHIJK','LMNOP'];
if (invalidkeyreservation.indexOf($("input.reservationkey").val()) > -1) {
BootstrapDialog.show(return $content;}
} else{
window.location.href = "/branches/Cancelaciones/Seleccion.html";
}
关于javascript - 输入值等于/匹配带有字符串的声明数组中的任何值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44977392/