开发者

Javascript Document.bgColor does not work

开发者 https://www.devze.com 2022-12-27 22:15 出处:网络
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 ?

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

精彩评论

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