简体   繁体   English

Javascript代码在Safari上不起作用

[英]Javascript code doesn't work on Safari

I have a script running on my index.html page. 我在index.html页面上运行了一个脚本。 It works perfectly for other browsers except Safari. 它非常适合Safari以外的其他浏览器。 Any idea why? 知道为什么吗? My script check the input of the User and see if it matches any of the postal codes in the array. 我的脚本检查User的输入,并查看它是否与数组中的任何邮政编码匹配。 If it matches it'll redirect user to a new page. 如果匹配,则会将用户重定向到新页面。 If it doesn't match, i'll show a hidden message. 如果不匹配,我将显示一条隐藏消息。

<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>

Maybe you can change: $("#postal-code-not-found").css("visibility","visible"); setTimeout(function() { $("#postal-code-not-found").css("visibility","hidden"); },3000); 也许您可以更改: $("#postal-code-not-found").css("visibility","visible"); setTimeout(function() { $("#postal-code-not-found").css("visibility","hidden"); },3000); $("#postal-code-not-found").css("visibility","visible"); setTimeout(function() { $("#postal-code-not-found").css("visibility","hidden"); },3000);

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM