IE不喜欢的那些事儿

来源:互联网 发布:java api 编辑:程序博客网 时间:2024/06/02 07:43

创建一个style,在其它browser中会很简单,如下:

dojo.create('style', {innerHTML : "h1 {font-size:12px;}"}, dojo.body());
如果这段程序放在IE中运行,即便是最新的IE 9,也会报错,而且是未知的运行时错误!在IE中只能这样创建:
var style = document.createElement('style');var rules = document.createTextNode( '#_lsgr_topbar {' +    '            width: 930px;' +    '        margin: 3px auto;' +    '        background-color: #369;' +    '        height: 25px;' +    '        text-align: center;' +    '        padding: 0px;' +    '        color: snow;' +    '        line-height: 25px;' +    '    }' +    '' +    '#_lsgr_topbar .top-item{' +    '    margin-left: 10px;' +    '    float : left;' +    '    cursor: pointer;' +    '}');style.type = 'text/css';if(style.styleSheet)    style.styleSheet.cssText = rules.nodeValue;else style.appendChild(rules);dojo.body().appendChild(style);

在IE中,模式名的属性名曾经为'className',从IE8起变为'class':

喜欢这篇文章?阳光宝盒就是为IE开发的天涯助手和搜狐助手,去看看吧。


var className = (!is_ie7 && !is_ie6) ? 'class' : 'className';
另一个跟这个有关的,在其它浏览器中,你可以对任何一种类型的元素的class属性赋值,但在IE中这样操作则会出错:
var node = dojo.create('div');dojo.addClass(node, 'hideMe');
上面的代码在所有browser中都能通过。但如果node是通过查询出来的,且有可能为其它(nodeType != 1)类型的话,则在IE中会出错。
dojo.query("body *").forEach(function(node){    if (node.nodeType == 1){dojo.addClass(node, 'hideMe');    }});
如果不作上述判断,则在IE中会报不支持的方法和属性错误。
原创粉丝点击