javascript - 为什么我的 if-else 语句不起作用?

标签 javascript url if-statement

谁能明白为什么这不起作用:

<script>
  if (url==showbasket.html||order1.html||order2.html||order3.html||order4.html) {
     document.write('<span style="font-family:lucida;font-size:10px;">Hello</span>');
  } else {
     document.write('<span style="font-family:lucida;font-size:30px;">Hello Hello</span>');
  }
</script>

我正在尝试编写一个脚本来执行此操作:

IF URL = 1.html or 2.html or 3.html or 4.html THEN 
    write option1 
ELSE 
    write option2 (for all other URL´s)

最佳答案

if (url == "showbasket.html" || url == "order1.html" || url == "order2.html" || url == "order3.html" || url == "order4.html")

您必须检查每个网址,如果它是字符串,请使用引号

关于javascript - 为什么我的 if-else 语句不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6505318/

相关文章:

jsf - 使用三元运算符实现EL中的else if - jsf

javascript - vuex:从异步函数设置默认值

javascript - 检测浏览器当前 "media"模式

java - Android 中取消缩短 URL

javascript - 使用javascript更改url并修改历史记录?

javascript - 在 Javascript 中通过多个 if 语句运行 While 循环

MySQL - 条件查询,语句结果

javascript - javascript是否禁止将输入类型从密码更改为密码?

javascript - ng-src 无法正常工作,但 src 工作正常

php - '?doing_wp_cron='