javascript - 原型(prototype) Javascript 错误(仅在 IE 中) 'Object doesn' t 支持此属性或方法'

标签 javascript internet-explorer prototypejs

我们的一位开发人员一起使用了一个横幅旋转器,虽然它在 NOT IE 中工作正常,但 IE 在第 30 行抛出错误(下面标记为“***** ERROR ON NEXT LINE”)。我可以不排序 $$('.banner') 吗?

错误是: “对象不支持此属性或方法”

使用原型(prototype) 1.6.0.3

function changeBanners() {

  // banners are now sorted by their z index so that
  // the ones most in front should be most on top in the DOM
  // ***** ERROR ON NEXT LINE

  banners = $$('.banner').sort(function (a,b){
    _a = parseInt(a.style.zIndex);
    _b = parseInt(b.style.zIndex);
    return _a < _b ? 1 : _a > _b ? -1 : 0;
  });

  // increment z index on all of the banners
  Element.extend(banners);

  banners.each( function (banner){

    Element.extend(banner);
    banner.style.zIndex = parseInt(banner.style.zIndex) + 1;
  });

  // move the first banner to be the last
  first_banner = banners.shift();
  banners.push(first_banner);

  // set it invisible
  Effect.toggle( first_banner.id , 'appear' , {
    duration: 2.0,
    afterFinish: function(){
      first_banner.style.zIndex = 0;  // update its z index so that it is at the end in the DOM also
      first_banner.show();            // make it reappear so that when the one in front of it disappears, it will show through
    }
  });
};

最佳答案

*叹息*

毕竟,这是我不记得在 JS 中声明变量

更改:

banners = $$('.banner').sort(function (a,b){
    _a = parseInt(a.style.zIndex);
    _b = parseInt(b.style.zIndex);
    return _a < _b ? 1 : _a > _b ? -1 : 0;
  });

至:

var banners = $$('.banner').sort(function (a,b){
    _a = parseInt(a.style.zIndex);
    _b = parseInt(b.style.zIndex);
    return _a < _b ? 1 : _a > _b ? -1 : 0;
  });

工作正常。

关于javascript - 原型(prototype) Javascript 错误(仅在 IE 中) 'Object doesn' t 支持此属性或方法',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3380173/

相关文章:

javascript - 删除 json 对象中的数组项的问题

jquery - magento 使用 jquery 且无冲突

javascript - 服务器在 ajax 调用上返回空响应可能是路由错误

javascript - 通过为特定的 div 标签使用 javascript 创建表单

javascript - window.onbeforeunload 没有返回任何值的任何不良副作用?

html - Facebook 应用程序中的内部链接 - 在 IE 中不起作用

javascript - 通过 id 隐藏 block

javascript - 我需要使用 Prototype 来做一些我可以在 jQuery 中轻松完成的事情

javascript - 在 Chrome 中上传文件时点击 'Cancel' 清除值

javascript - IE9 jQuery 图像大小?