JavaScript basics
JavaScript document.bgColor Get or change the background color of the webpage
JavaScript document.bgColor can be used to query the color code of the background color of the webpage, or to change the background color. It is part of the JavaScript Document content object collection. This example is divided into two parts. The first is to query the background through document.bgColor Color, then try to modify the background color, please see the following example.
JavaScript document.bgColor example of querying and changing the background color of a webpage
<html>
<body id="TestPage" bgcolor="blue">
<input type="button" onclick="CheckBgColor()" value="Query background color">
<input type="button" onclick="ChengeBgColor()" value="Change background color">
<script type="text/javascript">
function CheckBgColor(){
alert(document.getElementById("TestPage").bgColor);
}
function ChengeBgColor(){
document.bgColor="gray";
}
</script>
</body>
</html>
<body id="TestPage" bgcolor="blue">
<input type="button" onclick="CheckBgColor()" value="Query background color">
<input type="button" onclick="ChengeBgColor()" value="Change background color">
<script type="text/javascript">
function CheckBgColor(){
alert(document.getElementById("TestPage").bgColor);
}
function ChengeBgColor(){
document.bgColor="gray";
}
</script>
</body>
</html>
At the beginning of the example, the background color of the webpage is set to blue, bgcolor="blue" in the <body> tag, and then two buttons are prepared to query and change the background color. When the query is first started, the dialog window will pop up Tell you that the color is blue, and then press to change the background color, and the query will become gray again!
Post a Comment
0 Comments