gpt4 book ai didi

javascript - IE 不支持 Array includes 或 String includes 方法

转载 作者:IT王子 更新时间:2023-10-29 03:05:48 25 4
gpt4 key购买 nike

我一直在从事一个项目并开发一个 JavaScript 框架。原始代码大约有 700 行,所以我只粘贴了这一行。 includes 方法在 Internet Explorer 上不起作用。有解决办法吗?

var row_cells = tbl_row.match(/<td[\s\S]*?<\/td>/g);

row.Cells = new Array();
if (onRowBindFuncText != null) { /*Fonksyon tanımlanmaışsa daha hızlı çalış*/

var cellCount = 0;
for (i = 0; i < row_cells.length; i++) {

var cell = new Cell();
$.each(this, function (k, v) {

if ((row_cells[i]+"").includes("#Eval(" + k + ")")) {

cell.Keys.push(new Key(k,v));

...代码继续

最佳答案

因为它在 IE 中不受支持,所以在 Opera ( see the compatibility table ) 中也不支持,但您可以使用建议的 polyfill :

Polyfill

This method has been added to the ECMAScript 2015 specification and may not be available in all JavaScript implementations yet. However, you can easily polyfill this method:

if (!String.prototype.includes) {
String.prototype.includes = function(search, start) {
'use strict';
if (typeof start !== 'number') {
start = 0;
}

if (start + search.length > this.length) {
return false;
} else {
return this.indexOf(search, start) !== -1;
}
};
}

关于javascript - IE 不支持 Array includes 或 String includes 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31221341/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com