Javascript 动态添加样式在IE上不起作用
My函数动态创建元素并添加样式Javascript 动态添加样式在IE上不起作用,javascript,Javascript,My函数动态创建元素并添加样式 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) {
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中工作?你能在中断时显示
sty_le
和k
的值吗?底部:右:px好,我想问题是对的:px在哪里无效。谢谢:)为什么人们要编辑2013年的问题,这是一个明显的打字错误问题。快关上它