在JavaScript中无法创建多个if条件? [英] Can't make multiple if conditions in JavaScript?

查看:108
本文介绍了在JavaScript中无法创建多个if条件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我完全不知道为什么这不起作用。对我没用。

I have absolutely no idea why this is not working. Makes no sense to me.

这会返回语法错误:解析错误:

This returns a "syntax error: parse error":

if ($(this).attr("id") === 'search' || opening = true) return false;

为了更好的衡量,我也尝试了以下结果,产生了相同的结果:

For good measure, I also tried the following, which yielded the same result:

if (1 = 1 && 2 = 2) { return false; }


推荐答案

有三种不同的运营商在玩:

There are three different operators at play:


  • = :赋值

  • == :平等

  • === :严格平等

  • =: assignment
  • ==: equality
  • ===: strict equality

= 实际修改变量,所以你不应该使用它在中如果语句。也就是说,你应该使用 ... ||打开== true)而不是 ... || opening = true)

= actually modifies a variable, so you shouldn't use it inside if statements. That is, you should use ... || opening == true) instead of ... || opening = true).

这篇关于在JavaScript中无法创建多个if条件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆