【问题标题】:JS If statement not working on android 4.4.2 or iphoneJS If 语句不适用于 android 4.4.2 或 iphone
【发布时间】:2014-10-21 19:59:30
【问题描述】:

在我的 android 或 iPhone 上,当我在计算机上输入 glass 时,我会得到 else,它工作正常

<script type="text/javascript">
var x = prompt("Wholesale users enter in the password or hit enter for consumer information "," ");
if(x == "glass"){
    window.alert("sometext");
    }
else {
    window.alert("else");
}
 </script>

【问题讨论】:

  • 您能否更清楚地了解您所说的“不工作”是什么意思。
  • 在我的 android 或 iPhone 上,当我在电脑上输入 glass 时,我会得到 else,它工作正常

标签: javascript android iphone


【解决方案1】:
if([x] == "glass"){

应该是

if(x == "glass"){

当您执行[x] 时,您正在创建一个数组。由于您使用的是 == 检查它会是真的。 === 这不会是真的。


并且从 cmets 有一个 %20 又名空格

更改提示,使其中没有空格

r information "," ");

r information ","");

【讨论】:

  • 对不起,我正在尽一切努力让它工作,但不管怎样都行不通
  • alert(escape(x)); 它显示什么?
  • 有你的答案,有空格!
  • 感谢您的进一步解释!我已经排除了所有的可能性并且它起作用了,所以不确定..
猜你喜欢
  • 2023-04-03
  • 1970-01-01
  • 1970-01-01
  • 2021-09-28
  • 2018-08-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多