简体   繁体   English

对象不支持属性或方法“匹配”-jQuery / ie8

[英]Object doesn't support property or method 'match' - jQuery / ie8

I am using the following code to write on a cookie, it works pretty well on all browsers except ie8: 我正在使用以下代码在Cookie上编写代码,它在除ie8之外的所有浏览器上都可以正常运行:

var x = $.cookie(printedcookie); //991_0|590_0|995_0|996_0|564_0
var y = $.cookie(cookie);  // 991~1.20~/assets/img1.jpg|564~1.50~/assets/img2.jpg|201~1.10~/assets/img3.jpg|999~1.20~/assets/img4.jpg

var needles = x.split('|')
var haystack = y.split('|');
var newArray = $(haystack).filter(function (value) {
    for (var ii=0; ii<needles.length; ii++) {
        var needle = needles[ii].split('_')[0];
        var needleRegex = new RegExp("^" + needle);
        if(value.match(needleRegex)) {
            return false;
        }
    }
    return true;
});
$.cookie(cookie,newArray.join('|'),{ path: '/' , domain:domain, expires:365 });

I am expecting the final output to be: 我期望最终输出为:

201~1.10~/assets/img3.jpg|999~1.20~/assets/img4.jpg

What I am trying to achieve is: check if the first part of each item in var x is contained in y. 我想要实现的是:检查var x中每个项目的第一部分是否包含在y中。 If so remove this value, together with the remaining bit. 如果是这样,请删除该值以及剩余的位。

Any help would much be appreciated 任何帮助将不胜感激

IE throws an error : Error: Object doesn't support property or method 'match' IE抛出错误:错误:对象不支持属性或方法“匹配”

Instead of .match() you should use other alternative functions like 代替.match(),您应该使用其他替代函数,例如

contains(),

hasClass(),

etc .. according to your logic. 等..根据您的逻辑。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM