JavaScript, click button to change the page background and font color, the page has n color Change button. Click on different button, the page font and background will be changed to different colors.
Very easy JavaScript applet.
I. BASIC OBJECTIVES
Open a webpage first prompt greeting message "Hello"
The page has n change the color of the button, which is returned to return the default color of the page, the background is white, the font is black
Click on a different button. The font and background of the page will change to different colors.
Originally wanted to make a rainbow, but the principle of the same is not more than write button.
Second, the basic idea
The key is to provide ID to the body tag and the font JS. So that it is controlled in JS. This example provides an application to the JS function.
Third, the production process
For a simple little page, the details look at the gaze:
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">");} function unload () {alert ("Good-bye!") ");} function ChangeColor (Bcolor, Fcolor) {//= equivalent to the font <span style= "color: Fcolor passed over" > so. Change the color of the font document.getElementById ("Body"). Style.background = Bcolor;document.getelementbyid ("Ziti"). Style.color = Fcolor;} </script>
The onunload () function almost only works when IE closes this page. And this dialog box will not be at the forefront. Google Chrome has no effect whatsoever. So. This function has little meaning.
Copyright notice: This article Bo Master original article. Blog, not reproduced without consent.
"JavaScript" easy to change background and font Color page