开发者

Javascript Document.bgColor does not work

In the below code, I get the two dialog boxes, but the bgColor of the page is never changed. Is there any standard that font / color changes are not honored in JavaScript ?

 <html>
<head>
</head>

<body bgColor="GRAY">
<script type="text/javascript">
document.write("This message is written by JavaScript");
alert('Am here');
alert('Am here again');
document开发者_高级运维.bgcolor="WHITE";
</script>
</body>

</html>


bgColor is really, really old. Better use CSS values. And you need to address the body element, not the document.

This should work: document.body.style.backgroundColor = '#ffffff'


That's because it's bgColor and not bgcolor (note the case).

Also, using document.body.style.backgroundColor might be a better idea. And I would use hexadecimal instead of named colors :)

So, use #ffffff instead of WHITE.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜