js 클릭 하여 배경 색 이나 그림 을 바 꾸 는 인 스 턴 스 코드

5021 단어 배경색깔.그림.
1,버튼 스타일

<script>
org_Color=document.bgColor.substring(1.10)
</script>
<form>
<input type="button" value=" "onClick="document.bgColor='#feffc6'">
<input type="button" value=" "onClick="document.bgColor='#c6fffe'">
<input type="button" value=" "onClick="document.bgColor='#ffc9c6'">
<input type="button" value=" "onClick="document.bgColor='#508b7d'">
<input type="button" value=" "onClick="document.bgColor='#7BC7FF'">
<input type="button" value=" "onClick="document.bgColor='#f0f0f0'">
</form>
2,드 롭 다운 스타일

<selectonChange="document.bgColor=this.options[this.selectedIndex].value">
<option value="#C0C0C0">
<option value="BLACK">
<option value="d2c6ff">
<option value="feefc7">
<option value="ffd2c6">
<option value="c7fed8">
<option value="80ff80">
<option value="#C1BC59">
<option value="#7BC7FF">
<option value="#AEDFD3">
<option value="#508B7D">
<option value="#F0F0F0">
</select>
3,터치 스타일

<scriptlanguage="Javascript">
<!--
function backcolor(form){
temp = ""
for (var i = 0; i < 16; 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 > 44)
backgroundcolor = backgroundcolor - 45
else if (backgroundcolor > 29)
backgroundcolor = backgroundcolor - 30
else if (backgroundcolor > 15)
backgroundcolor = backgroundcolor - 16
if (backgroundcolor == 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 )
return "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 == 10 )
return "gray";
else if (backgroundcolor == 11 )
return "yellow";
else if (backgroundcolor == 12 )
return "aqua";
else if (backgroundcolor == 13 )
return "black";
else if (backgroundcolor == 14 )
return "white";
else if (backgroundcolor == 15 )
return "silver";
}
// -->
</script>
<body onload="document.bgColor='lime'; returntrue;">
<a href="javascript:void(0);"onmouseover="randombackground()"><fontsize="5" face=" "> </font></a>

클릭 하여 배경 그림 바 꾸 기:

<div style="float:right;margin-right:20px;">
<ahref="javascript:void(0);"><imgclass="button1"onClick="javascript:document.body.style.background='url(images/bg/1.jpg)'"></a>
<ahref="javascript:void(0);"><imgclass="button2"onClick="javascript:document.body.style.background='url(images/bg/2.jpg)'"></a>
<ahref="javascript:void(0);"><imgclass="button3"onClick="javascript:document.body.style.background='url(images/bg/3.jpg)'"></a>
<ahref="javascript:void(0);"><imgclass="button4"onClick="javascript:document.body.style.background='url(images/bg/4.jpg)'"></a>
<ahref="javascript:void(0);"><imgclass="button5"onClick="javascript:document.body.style.background='url(images/bg/5.jpg)'"></a>
<ahref="javascript:void(0);"><imgclass="button6"onClick="javascript:document.body.style.background='url(images/bg/6.jpg)'"></a>
</div>
IE6 가 사용 할 수 없 는 해결 방법:

<imgonClick="javascript:document.body.style.background='url(images/bg/1.jpg)';returnfalse;">

좋은 웹페이지 즐겨찾기