简体   繁体   中英

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:

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. 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'

Instead of .match() you should use other alternative functions like

contains(),

hasClass(),

etc .. according to your logic.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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