javascript

位置:IT落伍者 >> javascript >> 浏览文章

js点击更换背景颜色或图片的实例代码


发布日期:2024年02月08日
 
js点击更换背景颜色或图片的实例代码

按钮样式

复制代码 代码如下:
<script>
org_Color=documentbgColorsubstring()
</script>
<form>
<input type="button" value="淡黄色背景"onClick="documentbgColor=#feffc">
<input type="button" value="浅蓝色背景"onClick="documentbgColor=#cfffe">
<input type="button" value="粉红色背景"onClick="documentbgColor=#ffcc">
<input type="button" value="墨绿色背景"onClick="documentbgColor=#bd">
<input type="button" value="天蓝色背景"onClick="documentbgColor=#BCFF">
<input type="button" value="米白色背景"onClick="documentbgColor=#fff">
</form>


下拉样式

复制代码 代码如下:
<selectonChange="documentbgColor=thisoptions[thisselectedIndex]value">
<option value="#CCC">灰色的
<option value="BLACK">黑的色
<option value="dcff">淡紫蓝
<option value="feefc">太阳黄
<option value="ffdc">淡红橘
<option value="cfed">苹果绿
<option value="ff">草原绿
<option value="#CBC">橄榄色
<option value="#BCFF">天空蓝
<option value="#AEDFD">蓝绿色
<option value="#BD">墨绿色
<option value="#FFF">米白色
</select>


触碰样式

复制代码 代码如下:
<scriptlanguage="Javascript">
<!
function backcolor(form){
temp = ""
for (var i = ; i < ; i++) {
temp = formcolor[i]value
if (formcolor[i]checked){ documentbgColor = temp }
}
}

function randombackground(){
documentbgColor = getColor()
}

function getColor(){
currentdate = new Date()
backgroundcolor = currentdategetSeconds()
if (backgroundcolor > )
backgroundcolor = backgroundcolor
else if (backgroundcolor > )
backgroundcolor = backgroundcolor
else if (backgroundcolor > )
backgroundcolor = backgroundcolor
if (backgroundcolor == )
return "olive";
else if (backgroundcolor == )
return "teal";
else if (backgroundcolor == )
return "red";
else if (backgroundcolor == )
return "blue";
else if (backgroundcolor == )
return "maroon";
else if (backgroundcolor == )
return "navy";
else if (backgroundcolor == )
return "lime";
else if (backgroundcolor == )
return "fuschia";
else if (backgroundcolor == )
return "green";
else if (backgroundcolor == )
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="documentbgColor=lime; returntrue;">
<a   href="javascript:void();"onmouseover="randombackground()"><fontsize=""  face="宋体">碰我改变背景颜色</font></a>

点击更换背景图片

复制代码 代码如下:
<div style="float:right;marginright:px;">
<ahref="javascript:void();"><imgclass="button"onClick="javascript:documentbodystylebackground=url(images/bg/jpg)"></a>
<ahref="javascript:void();"><imgclass="button"onClick="javascript:documentbodystylebackground=url(images/bg/jpg)"></a>
<ahref="javascript:void();"><imgclass="button"onClick="javascript:documentbodystylebackground=url(images/bg/jpg)"></a>
<ahref="javascript:void();"><imgclass="button"onClick="javascript:documentbodystylebackground=url(images/bg/jpg)"></a>
<ahref="javascript:void();"><imgclass="button"onClick="javascript:documentbodystylebackground=url(images/bg/jpg)"></a>
<ahref="javascript:void();"><imgclass="button"onClick="javascript:documentbodystylebackground=url(images/bg/jpg)"></a>
</div>

IE不能用的解决方法

复制代码 代码如下:


<imgonClick="javascript:documentbodystylebackground=url(images/bg/jpg);returnfalse;">

               

上一篇:JScript对象

下一篇:Js控制弹窗实现在任意分辨率下居中显示