回答
String.prototype.includes
是,你写,在Internet Explorer(或Opera)不支持
相反,你可以使用String.prototype.indexOf
。 #indexOf
返回子字符串的第一个字符的索引(如果它在字符串中),否则返回-1
。 (很像阵列当量)
var myString = 'this is my string';
myString.indexOf('string');
// -> 11
myString.indexOf('hello');
// -> -1
MDN具有使用indexOf
为includes
一个填充工具:https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/String/includes#Polyfill
包括()不被大多数浏览器支持。你的选择是要么使用
从MDN -polyfill https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/String/includes
或使用
-indexof()
var str = "abcde";
var n = str.indexOf("cd");
它给你N = 2
这是广泛支持。
这个正确答案。使用来自MDN的聚合物 – Sangar82
如果您使用MDN中的polyfill,_do不会用'for ... in'!_来迭代您的字符串,如果您像这样定义它,它将遍历'String.prototype.includes'。 –
或者只是把这个JavaScript文件中,有一个美好的一天:)
String.prototype.includes = function (str) {
var returnValue = false;
if (this.indexOf(str) !== -1) {
returnValue = true;
}
return returnValue;
}
如果你使用这个polyfill,不要用'for ... in'迭代你的字符串,如果它是这样定义的,它将遍历'String.prototype.includes'。 –
如果你想使用Array.prototype.include()
在JavaScript中,你可以使用这个脚本来保持: github-script-ie-include ,自动将包括转换()匹配()函数,如果它检测到IE。
其他选项始终使用string.match(Regex(expression))
- 1. 为什么Internet Explorer不支持includes()?
- 2. 表单不能在Internet Explorer中工作
- 3. .html()不能在Internet Explorer中工作
- 4. 脚本不能在Internet Explorer中工作
- 5. JavaScript不能在Internet Explorer中工作
- 6. appendChild在Internet Explorer中不工作
- 7. jQuery不能在Internet Explorer中工作
- 8. Jquery .get()不能在Internet Explorer中工作
- 9. 锚不会在Internet Explorer中工作11
- 10. 面具不能在Internet Explorer中工作
- 11. MouseEvent不能在Internet Explorer中工作
- 12. addClass和removeClass在Internet Explorer中不工作
- 13. $ state.go不能在Internet Explorer中工作
- 14. Request.Params Request.Form不能在Internet Explorer中工作
- 15. grails链接在Internet Explorer中不工作
- 16. FadeIn和FadeOut在Internet Explorer中不工作
- 17. animate()不能在Internet Explorer中工作
- 18. JavaScript不能在Internet Explorer中工作
- 19. externalInterface javascript在Internet Explorer 11中不工作
- 20. JS不能在Internet Explorer中工作
- 21. WebSockets在Internet Explorer 10中不工作
- 22. jwplayer在Internet Explorer中不工作
- 23. History.js不能在Internet Explorer中工作
- 24. html网站在Internet Explorer中不工作
- 25. 悬停在Internet Explorer中不工作
- 26. ClickOnce在Internet Explorer 9中不工作
- 27. scrollLeft在Internet Explorer中不工作
- 28. JSON - 在Internet Explorer 8中不工作
- 29. JQuery的removeCookie不工作在Internet Explorer 7
- 30. bootstrap不工作在Firefox/Internet Explorer
在Opera 46.0它的工作原理 –