JS Click to replace the background color or picture of the instance code

Source: Internet
Author: User
Tags getcolor touch

1, Button style

Copy Code code as follows:


<script>


org_color=document.bgcolor.substring (1.10)


</script>


<form>


<input type= "button" value= "Light yellow Background" onclick= "document.bgcolor= ' #feffc6 '" >


<input type= "button" value= "Light blue Background" onclick= "document.bgcolor= ' #c6fffe '" >


<input type= "button" value= "Pink Background" onclick= "document.bgcolor= ' #ffc9c6 '" >


<input type= "button" value= "Green Background" onclick= "document.bgcolor= ' #508b7d '" >


<input type= "button" value= "sky-blue background" onclick= "document.bgcolor= ' #7BC7FF '" >


<input type= "button" value= "Rice white background onclick=" document.bgcolor= ' #f0f0f0 ' ">


</form>


2, drop down style

Copy Code code as follows:


<selectonchange= "Document.bgcolor=this.options[this.selectedindex].value" >


<option value= "#C0C0C0" > Grey


<option value= "Black" > Dark color


<option value= "d2c6ff" > Light violet Blue


<option value= "Feefc7" > Sun yellow


<option value= "ffd2c6" > Reddish orange


<option value= "C7fed8" > Apple green


<option value= "80ff80" > Grassland green


<option value= "#C1BC59" > Olive


<option value= "#7BC7FF" > Sky blue


<option value= "#AEDFD3" > Blue-Green


<option value= "#508B7D" > Dark green


<option value= "#F0F0F0" > M white


</select>


3, Touch style

Copy Code code as follows:


<scriptlanguage= "Javascript" >


<!--


function BackColor (form) {


temp = ""


for (var i = 0; i < i++) {


temp = Form.color[i].value


if (form.color[i].checked) {document.bgcolor = temp}


}


}

function Randombackground () {
Document.bgcolor = GetColor ()
}

Function GetColor () {
currentdate = new Date ()
BackgroundColor = Currentdate.getseconds ()
if ( BackgroundColor >)
BackgroundColor = backgroundcolor-45
Else if (BackgroundColor >)
Backgroundco Lor = backgroundcolor-30
Else if (BackgroundColor >)
backgroundcolor = backgroundcolor-16
if (backgr Oundcolor = = 0)
return "Olive";
else if (backgroundcolor = = 1)
return "teal";
else if (backgroundcolor = = 2)
return "Red";
else if (backgroundcolor = 3)
return "Blue";
else if (backgroundcolor = 4)
RET Urn "Maroon";
Else if (backgroundcolor = 5)
Return "Navy";
Else if (backgroundcolor = = 6)
return "lime";
Else if (BackgroundColor = 7)
return "Fuschia";
Else if (backgroundcolor = 8)
return "green";
else if (backgroundcolor = = 9)
return "purple";
Else if (backgroundcolor = =)
return "Gray";
else if (backgroundcolor = =)
Return yellOw ";
Else if (backgroundcolor = =)
return "Aqua";
Else if (backgroundcolor =)
return "BLACK";
Else if (backgroundcolor = =)
return "white";
else if (backgroundcolor = =)
return "silver";
}
//;
</script>
<body onload= "document.bgcolor= ' lime '; returntrue;"
<a href= "javascript:void (0);" Onmouseover= "Randombackground ()" ><fontsize= "5" face= "Song body" > Touch Me change background color </font></a>

Click to change background picture:

Copy Code code as follows:


&lt;div style= "float:right;margin-right:20px;" &gt;


&lt;ahref= "javascript:void (0);" &gt;&lt;imgclass= "Button1" onclick= "javascript:document.body.style.background= ' url (images/bg/1.jpg) '" &gt;&lt;/a &gt;


&lt;ahref= "javascript:void (0);" &gt;&lt;imgclass= "Button2" onclick= "javascript:document.body.style.background= ' url (images/bg/2.jpg) '" &gt;&lt;/a &gt;


&lt;ahref= "javascript:void (0);" &gt;&lt;imgclass= "Button3" onclick= "javascript:document.body.style.background= ' url (images/bg/3.jpg) '" &gt;&lt;/a &gt;


&lt;ahref= "javascript:void (0);" &gt;&lt;imgclass= "Button4" onclick= "javascript:document.body.style.background= ' url (images/bg/4.jpg) '" &gt;&lt;/a &gt;


&lt;ahref= "javascript:void (0);" &gt;&lt;imgclass= "Button5" onclick= "javascript:document.body.style.background= ' url (images/bg/5.jpg) '" &gt;&lt;/a &gt;


&lt;ahref= "javascript:void (0);" &gt;&lt;imgclass= "Button6" onclick= "javascript:document.body.style.background= ' url (images/bg/6.jpg) '" &gt;&lt;/a &gt;


&lt;/div&gt;

IE6 solutions are not available:

Copy Code code as follows:


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.