Javascript代码在Safari上不起作用

时间:2016-06-04 00:45:58

标签: javascript jquery safari

我的index.html页面上运行了一个脚本。它适用于除Safari之外的其他浏览器。知道为什么吗? 我的脚本检查用户的输入,看它是否与数组中的任何邮政编码匹配。如果匹配,则会将用户重定向到新页面。如果不匹配,我会显示一条隐藏的消息。

<script>
  // CHECK IF USER WITHIN DELIVERY AREA
  function checkAnswer(){
        var postalCode = ["V5K", "V5M","V5R","V5S","V5L"]
    var response = document.getElementById('answer').value;
    for (var i = 0; i < postalCode.length; i++) {
      if (response.substring(0,3).toUpperCase() == postalCode[i]) {
        location = '/postal-code-area';
        break 
      } 
      if (postalCode.every(elem => elem !== response.substring(0,3).toUpperCase())) {
            $("#postal-code-not-found").css("visibility","visible");
            setTimeout(function() {
                $("#postal-code-not-found").css("visibility","hidden");
            },3000);
      }
    }
    return false;
  }
</script>

1 个答案:

答案 0 :(得分:0)

也许你可以改变: $("#postal-code-not-found").css("visibility","visible"); setTimeout(function() { $("#postal-code-not-found").css("visibility","hidden"); },3000);

于: $("#postal-code-not-found").css("display","block"); setTimeout(function() { $("#postal-code-not-found").css("display","none"); },3000);