JavaScript中的匹配变量

JavaScript中的匹配变量,javascript,Javascript,如果x变量有文本“我在这里有正确的文本”,但我的代码不起作用,则以下代码段应显示警报。为什么? var x = "Im the variable and I have right text right here"; if ("x:contains("I have right text right here").lenght > 0") { alert("Match") } indexOf()方法返回字符串中指定值第一次出现的位置 var x = "Im the variable a

如果
x
变量有文本“我在这里有正确的文本”,但我的代码不起作用,则以下代码段应显示警报。为什么?

var x = "Im the variable and I have right text right here";

if ("x:contains("I have right text right here").lenght > 0") {
  alert("Match")
}
indexOf()
方法返回字符串中指定值第一次出现的位置

var x = "Im the variable and I have right text right here";

if ( x.indexOf("I have right text right here")  > 0 ) {
  alert("Match")
}
您可以使用:


请在javascript中查找字符串连接。你遗漏了一件非常小但非常重要的事情。同时检查你的代码中长度的拼写,顺便说一句,你应该学会如何调试js:我是唯一一个觉得这个问题的质量很低并且不应该得到支持的人吗?
    var x = "Im the variable and I have right text right here";

    if ( x.includes("I have right text right here")) {
        alert("Match")
    }