IE不支持数组包含或字符串包含方法 [英] IE does not support Array includes or String includes methods

查看:219
本文介绍了IE不支持数组包含或字符串包含方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在从事一个项目并开发JavaScript框架.原始代码约为700行,因此我仅粘贴了这一行. include方法在Internet Explorer上不起作用.有什么解决办法吗?

I have been working on a project and developing a JavaScript framework. The original code is about 700 lines so I only pasted this line. The includes method doesn't work on Internet Explorer. Is there any solution for this?

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中也不支持它(

Because it's not supported in IE, it is not supported also in Opera (see the compatibility table), but you can use the suggested polyfill:

填充

此方法已添加到ECMAScript 2015规范中,可能并非在所有JavaScript实现中都可用.但是,您可以轻松地填充此方法:

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;
    }
  };
}

这篇关于IE不支持数组包含或字符串包含方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆