Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/430.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 带有字符串问题的If语句_Javascript_String_If Statement - Fatal编程技术网

Javascript 带有字符串问题的If语句

Javascript 带有字符串问题的If语句,javascript,string,if-statement,Javascript,String,If Statement,这是我的代码(我正在编辑Xsplit中用于解析html文件的脚本,我正在尝试将最终变量-responseEdited设置为“无活动匹配”。如果变量-responseEdited-包含字符串“winning”。但是,下面代码的结果在该变量中似乎为null /*replace some text in the string*/ var responseEdited = responseCleaned.replace('</h3><h3>', 'vs. '); /*this

这是我的代码(我正在编辑Xsplit中用于解析html文件的脚本,我正在尝试将最终变量-responseEdited设置为“无活动匹配”。如果变量-responseEdited-包含字符串“winning”。但是,下面代码的结果在该变量中似乎为null

/*replace some text in the string*/
var responseEdited = responseCleaned.replace('</h3><h3>', 'vs. ');

/*this is the problem area*/
/*if it contains "winning", change to no active match*/
if(responseEdited.contains("winning"))
   {
     responseEdited = "No active match.";
   }
/*替换字符串中的某些文本*/
var responseEdited=ResponseClean.替换(“”,'vs.);
/*这就是问题所在*/
/*如果包含“获胜”,则更改为无活动比赛*/
if(responseEdited.contains(“winning”))
{
responseEdited=“无活动匹配。”;
}

想法?谢谢!

要使您的代码在不更改的情况下工作,只需在脚本顶部添加以下polyfill。如果该函数存在于特定浏览器的JavaScript引擎中,则该函数将被忽略,否则该函数将添加到String的原型中

String.prototype.contains()

这就是。

我的第一个想法是,你不应该把JavaScript代码放在Java程序中。它是程序的一部分,设计用于自定义html解析的可编辑JavaScript(有一个内置编辑器)。它是JavaScript代码。所以请不要放“Java”标记它。你想让JavaScript专家看看你的问题,对吗?如果我没有if语句,它会起作用。使用
responseEdited.indexOf(“winning”)>-1
if (!String.prototype.includes) {
  String.prototype.includes = function() {'use strict';
    return String.prototype.indexOf.apply(this, arguments) !== -1;
  };
}