回答
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它的工作原理 –