"JavaScript" easy to change background and font Color page

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.