JS 在IE8兼容模式下设置属性不能显示

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


图片垂直居中 function test(id) { var div1 = document.getElementById(id); var div2 = document.createElement("div"); div2.setAttribute("style","border:1px solid red;width:30px;height:20px;margin:3px;"); div2.setAttribute("onclick","javascript:alert('提示消息!');"); div1.insertBefore(div2, div1.firstChild); }





</div>


呃。。。onclick也不支持这样设置
参考: [url]http://www.lnwest.com/program/article.asp?id=631[/url]

直接写成这样吧:
div2.onclick = function(){
alert("提示消息");
}

弱弱问一下,你所说的属性是指你JavaScript里面设置的全部属性还是你html标签里面的属性?还是两者的属性都不能显示?

参考: [url]http://methodmissing.iteye.com/blog/407768[/url]
IE不支持直接给style设置样式字串,而要写成这样:
dom.style.cssText = "xxxx"