我的函数动态创建一个元素并添加样式
create:function(el,attr,sty_le){
this.elem=document.createElement(el);
for(var k in attr){
if(attr.hasOwnProperty(k)){
this.elem.setAttribute(k,attr[k]);
}
}
for (var k in sty_le) {
if (sty_le.hasOwnProperty(k)) {
this.elem.style[k]=sty_le[k];
}
}
return this.elem;
}
这似乎在Firefox、Chrome和Opera上完美运行,但Internet Explorer显示以下错误:
消息:无效的参数。行:20 字符:5 代码:0
其中第 20 行是:
this.elem.style[k]=sty_le[k];
我怎样才能让它在 IE 中工作?