js 改变div 背景颜色问题

来源:百度知道 编辑:UC知道 时间:2024/06/19 18:28:17
<div id="a"></div>

改变div 背景颜色

document.getElementById('a').style.backgroundColor="#FF0000";

这样写有错吗?提示说,此对象不支此属性或方法!!
请问应该怎么写??

这样写试一试
document.getElementById('a').style.background="#FF0000";

你那样也没有错 我这可以运行

var div=document.getElementById(divid);
div.style.backgroundColor= "#FF0000";

我这么做没错。试试看

function printPage(obj) {// wsdl sample portal export printWebId
document.body.style.backgroundColor = "#FFFFFF";// 打印时设置背景颜色为白色
}

这么写没错.

你确定是提示这一句?