【问题标题】:IE9 prototype mouseover and mouseout mismatchIE9 原型 mouseover 和 mouseout 不匹配
【发布时间】:2011-06-01 20:26:46
【问题描述】:

我在处理原型脚本时遇到了 IE9 的奇怪行为。 在这里,我根据鼠标悬停/移出设置了两种不同的不透明度样式:

window.onload = function(){
var freccia1 = $($$('.next_button')[0]);
freccia1.setStyle({opacity: '0.20'});       
freccia1.setStyle({filter: 'alpha(opacity=20)'});   
var freccia2 = $($$('.previous_button')[0]);
freccia2.setStyle({opacity: '0.20'});       
freccia2.setStyle({filter: 'alpha(opacity=20)'});
}

这在所有浏览器中都可以正常工作,包括以前的 IE 版本,但在 IE9 中却没有,它不会降低不透明度。它的控制台返回我:

无法获取属性 ' setStyle' 值:对象 null 或未定义

有谁知道为什么?谢谢

【问题讨论】:

    标签: internet-explorer-9 prototypejs mouseover


    【解决方案1】:

    如果您要使用 Prototype,您不妨尽可能多地使用它提供的功能,因为它考虑了浏览器兼容性,因此您不必这样做。

    试试这个(未经测试):

    document.observe('dom:loaded', function() {
        [$$('.next_button')[0], $$('.previous_button')[0]].each(function(ele) {
            $(ele).setStyle({
                opacity: '0.20',
                filter: 'alpha(opacity=20)'
            });
        });
    });
    

    【讨论】:

    • 感谢您的帮助,但您的代码返回给我:“$(ele).setStyle is undefined”...
    • @asnothingelse 你确定$$('.next_button')[0]$$('.previous_button')[0] 存在吗?
    【解决方案2】:

    您没有提及您正在运行哪个版本的原型。我在使用原型 1.5.0 的一个页面上遇到了类似的问题(请不要判断)。在 1.5.0 中,setStyle 和 getStyle 函数专门在处理 opacity/alpha(opacity) 时对 IE 进行浏览器检查。

    /MSIE/.test(navigator.userAgent)
    

    在我的例子中,setStyle 调用 getStyle('filter').replace()。不幸的是,getStyle('filter') 在 IE9 中返回 null,因此 .replace 会引发异常。

    IE 团队的一些相关说明:http://blogs.msdn.com/b/ie/archive/2010/08/17/ie9-opacity-and-alpha.aspx

    【讨论】:

      猜你喜欢
      • 2011-03-03
      • 1970-01-01
      • 2012-04-24
      • 2014-03-09
      • 2011-04-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多