开发者

jquery's every() doesn't work on Internet Explorer

开发者 https://www.devze.com 2022-12-29 13:50 出处:网络
When I run the following javascript in IE, I get \"Error: Object doesn\'t support this property or method\" on \"data.every(...)\".

When I run the following javascript in IE, I get "Error: Object doesn't support this property or method" on "data.every(...)".

It works in Chrome/Fire开发者_运维问答fox.

jquery's every() doesn't work on Internet Explorer


.every() is a JavaScript 1.6 enhancement to the Array prototype. Firefox supports this method in Gecko 1.8b2 and later, and here is a quick replacement if it doesn't exist.

From MDC:

every is a recent addition to the ECMA-262 standard; as such it may not be present in all browsers. You can work around this by inserting the following code at the beginning of your scripts, allowing use of every in implementations which do not natively support it. This algorithm is exactly the one used in Firefox and SpiderMonkey.

if (!Array.prototype.every)
{
  Array.prototype.every = function(fun /*, thisp*/)
  {
    var len = this.length >>> 0;
    if (typeof fun != "function")
      throw new TypeError();

    var thisp = arguments[1];
    for (var i = 0; i < len; i++)
    {
      if (i in this &&
          !fun.call(thisp, this[i], i, this))
        return false;
    }

    return true;
  };
}


There's no every method defined in jQuery. You could use each instead:

$.each(data, function(index, task) {
    createCardFromTask(task);
});

or a little shorter:

$.each(data, function() {
    createCardFromTask(this);
});


I recently had the same problem with .each function when I tried to loop through selection of DOM elements. Turns out the problem wasn't with Javascript. It was the HTML, a special tag we were using. ABBR, isn't supported by IE6.

I suggest you first check all your tags, make sure all tags are supported by IE6.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号