我们的一位开发人员一起使用了一个横幅旋转器,虽然它在 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/