Home > Web Front-end > JS Tutorial > How to set the page background color and background image in javascript_javascript skills

How to set the page background color and background image in javascript_javascript skills

WBOY
Release: 2016-05-16 15:22:45
Original
3074 people have browsed it

The example in this article describes how to set the background color and background image of the page using javascript. Share it with everyone for your reference, the details are as follows:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
<SCRIPT LANGUAGE=javascript>
function update(temp)
{
  if(temp == 'color')
  {
   document.body.style.backgroundColor="#FFFFFF";//改变背景色
  }
  if(temp == 'img')
  {
   document.body.style.backgroundImage="url(images/bgimg.gif)";//改变背景图片
  }
}
</SCRIPT>
</HEAD>
<BODY bgcolor="#CCFFFF">
<input type = button value="改变背景色" onclick="update('color')">
<input type = button value="改变背景图片" onclick="update('img')">
</BODY>
</HTML>

Copy after login

I hope this article will be helpful to everyone in JavaScript programming.

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template