[JavaScript] easily changes the webpage background and font color, and the javascript webpage background

Source: Internet
Author: User

[JavaScript] easily changes the webpage background and font color, and the javascript webpage background

JavaScript: click the button to change the color of the background and font of the webpage. There are N buttons for changing the color of the webpage. Click different buttons to change the font and background of the webpage to different colors. Simple JavaScript applet.

I. Basic Objectives


When you open the webpage, the system first prompts "hello"


There are N buttons in the webpage that change the color. The returned result is the default color of the webpage, the background is white, and the font is black.

Click different buttons to change the font and background of the webpage to different colors.

I wanted to make a rainbow, but I didn't need to write more buttons in the same principle.


Ii. Basic Ideas

The key is to provide an id for the body label and the font js to control it in js. This example provides applications for js functions.


Iii. Production Process

For details on a simple small page, see the notes:

<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 

The onunload () function is only valid when IE closes this page, and this dialog box is not at the frontend. Google Chrome does not have any effect. Therefore, this function is of little significance.



How does javascript change the text background color?

Try the following ..
<P id = "pTag"> This is the text in p </p>
Document. getElementById ("pTag"). style. backgroundColor = "red"

How does javascript change the background color?

You want:
Function border1 (color1 ){
$ ("Border1"). style. border = "1px solid #" + color1;
$ ("Border1"). style. borderTop = "5px solid #" + color1;
// Body background color:
Document. bgColor = "#" + color1;
}

In addition:. style. border = "1px solid #" + color1; it seems that the pixels, styles, and colors cannot be set. Of course, I have not read this carefully. You can use it on your own.

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.