JavaScript implementation changes the page background and font color _javascript tips

Source: Internet
Author: User

The examples in this article describe how JavaScript implements changes to the background and font color of a Web page. Share to everyone for your reference. The specific analysis is as follows:

JavaScript, by clicking the button to change the background and font color of the page, the page has n a change Color button, click on a different button, the page font and background will change to different colors. Very simple JavaScript applet.

I. BASIC OBJECTIVES

Open the page first prompts the greeting message "Hello"

There are n color-changing buttons in the Web page, which returns the default color of the page, the background is white, and the font is black.

Clicking on a different button will change the font and background of the page to different colors.

Originally wanted to make a rainbow, but the principle is exactly the same do not write a button.

Ii. Basic Ideas

The key is to the body tag and font JS to provide ID, so that it can be controlled in JS. This example provides an application to the JS function.

Third, the production process

For a simple little page, see the Notes for details:

Copy Code code as follows:
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 "/>
<title>js Change background color </title>
<!--This can also be separated into a JS file inside, but this code is too short, there is no need for-->
<script type= "Text/javascript" >
OnLoad is equivalent to the constructor of this web page, OnUnload is equivalent to the extraction function of this page
function Load () {
Alert ("Hello!") ");
}
function Unload () {
Alert ("Goodbye!") ");
}
function ChangeColor (Bcolor, Fcolor) {
Equivalent to the font <span style= "color: Passing Fcolor" >, changing the color of the font
document.getElementById ("Body"). Style.background = Bcolor;
document.getElementById ("Ziti"). Style.color = Fcolor;
}
</script>
<!--key to providing an ID,JS getElementById () method for entire Web pages and inline fonts can easily control things in CSS-->
<body onload= "Load ()" onunload= "Unload ()" id= "Body" >
<span id= "Ziti" >js</span>
<br/>
<!--notice that when you pass an argument in double quotes, the original double quotation mark becomes a single quote, and the onclick value is something that is triggered once you click this button-->
<input onclick= "ChangeColor (' #ff0000 ', ' #ffffff ')" type= "button"
Value= "Red"/>
<input onclick= "ChangeColor (' #ff9900 ', ' #ffffff ')" type= "button"
Value= "Orange"/>
<input onclick= "ChangeColor (' #ffff00 ', ' #000000 ')" type= "button"
value= "Yellow"/>
......
<input onclick= "ChangeColor (' #ffffff ', ' #000000 ')" type= "button"
Value= "Back"/>
</body>

OnUnload () function is almost only valid when IE closes this page, and this dialog box is not on the front end, Google Browser does not have any effect. Therefore, this function is of little significance.

About JS color Operation tips Interested friends can also refer to the online tools:

RGB Color Coding Generator

Online Web Color tool

RGB Color Query Matrix _ color code Table _ color of the English name Daquan

I hope this article will help you with your JavaScript programming.

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.