If语句出现字符串问题
If statement with string issues
这是我的代码(我正在编辑Xsplit中用于解析html文件的脚本,并且我正在尝试将最终变量-responseEdited设置为"No active match"。如果变量-resposeEdited包含字符串"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.";
}
想法?谢谢
要使代码在不更改的情况下工作,只需在脚本顶部添加以下polyfill即可。如果该函数存在于特定浏览器的JavaScript引擎中,那么这将被忽略,否则该函数将被添加到String的原型中。
String.prototype.contains()
if (!String.prototype.includes) {
String.prototype.includes = function() {'use strict';
return String.prototype.indexOf.apply(this, arguments) !== -1;
};
}
这是MDN建议的polyfill。
相关文章:
- 日期 ISO 日期字符串问题
- Angularjs-拆分字符串问题
- 字符串问题的javascript赋值
- If语句出现字符串问题
- 简单的php字符串问题(HTML和javascript)
- Javascript编号/字符串问题
- Google Charts - hAxis 上的数字/字符串问题(Jquery ajax JSON 数据)
- NodeJS MongoDB 连接字符串问题
- 多行字符串问题
- Javascript子字符串问题
- PhoneGap Android查询字符串问题
- 获取子字符串问题(js.或jquery)
- Javascript生成的字符串问题中的双引号
- C++11 std::regex_replace()创建带有特定字符串问题的regexp
- Imagecreatefromstring从javascript传入的字符串问题
- Javascript和查询字符串问题
- JQuery -奇数整数/字符串问题
- JavaScript转义字符串问题
- JQuery移动查询字符串问题在非pushState浏览器
- 匹配和替换javascript中的子字符串问题