javascript - 输入值等于/匹配带有字符串的声明数组中的任何值

标签 javascript arrays input

我有这个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/

相关文章:

mysql - Laravel/十月 : multidimensional array mysql

ios - 遍历数组时在 iOS 中发布更新标签

javascript - 使用javascript自动计算输入值的总和

regex - HTML5 输入模式搜索报价

xml - xslt中的输入参数

javascript - 嵌套 AJAX 和用户事件

JavaScript,在动态添加的元素上启用查询选择器

javascript - Angular-UI - 转换到相同状态更新 URL 但后退按钮损坏

javascript - JavaScript 中太多的递归

c - 访问结构内数组中的数据时出错