开发者社区 问答 正文

javascript window.location.href 跳转问题

请先看代码片段:
if(1>0){ window.location.href="a.html"; } if(1<0){ window.location.href="b.html"; }else{ window.location.href="c.html"; }
为什么不跳转 a.html,反而跳转到了c.html

展开
收起
小旋风柴进 2016-03-23 09:15:23 3972 分享 版权
1 条回答
写回答
取消 提交回答
  • 要写成

    if (1 > 0) {
    window.location.href = "a.html";
    } else if (1 < 0) {
    window.location.href = "b.html";
    } else {
    window.location.href = "c.html";
    }

    不然 第一个if 和 第二个else 都需要执行,结果是执行了第一个if后,再执行第二个else,最终结果就是跳转c.html

    2019-07-17 19:10:16
    赞同 展开评论
问答分类:
问答标签:
问答地址: