我在我的代码中使用 .include()
这在其他浏览器上工作正常但在 IE 中不工作。
if (feauture2_1_title.includes("Phase")) {
}
- 如果 IE 不支持任何替代品?
最佳答案
这是一个新功能。 The MDN提供一个 polyfill(你可以在自己的代码中包含一些代码来替换旧浏览器中的标准功能):
if (!Array.prototype.includes) {
Array.prototype.includes = function(searchElement /*, fromIndex*/ ) {
'use strict';
var O = Object(this);
var len = parseInt(O.length) || 0;
if (len === 0) {
return false;
}
var n = parseInt(arguments[1]) || 0;
var k;
if (n >= 0) {
k = n;
} else {
k = len + n;
if (k < 0) {k = 0;}
}
var currentElement;
while (k < len) {
currentElement = O[k];
if (searchElement === currentElement ||
(searchElement !== searchElement && currentElement !== currentElement)) {
return true;
}
k++;
}
return false;
};
}
但大多数情况下,您会对其中一种解决方案感到满意:
feauture2_1_title.indexOf("Phase")!==-1
或
/Phase/.test(feauture2_1_title)
关于javascript - .includes() 是未定义的 IE,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31913108/