当前位置:首页 > 建站知识 > 网站设计 > 正文

点击按钮改变网页背景图片

来源:征帆网络  作者:ymars  日期:2013-2-20

    我们希望点击一个按钮,改变网页背景图片,这样改怎么做呢?下面征帆网络给出代码,经过测试是可以使用的,不过建议大家的是:代码里面的圆角符号都要换成英文状态下的,使用查找替换可能会更好一点。

<html>
<head>
<title>点击按钮改变网页背景图片怎么做-来自于www.ymars.com</title>
<style type="text/css">
<!--
.bgimages {
color: #993333;
font-weight: bold;
width:60ox; height:28px; background:#eaeaea;
}
-->
</style>
</head>
<body bgcolor="#FFFFFF" leftmargin="0" marginwidth="0">
<script language="JavaScript1.2">
<!--
function tile(){
if (!document.all)
return
var source=event.srcElement
if (source.tagName=="IMG")
document.body.style.backgroundImage="url("+source.src+")"
}

function restore(){
document.body.style.backgroundImage=’’
}
document.body.ondblclick=restore
-->
</script>
</p>
<p align="center"><span class="bgimages" onClick="tile();event.cancelBubble=true"><span class="bgimages" onClick="tile();event.cancelBubble=true"><img src="http://www.ymars.com.cn/d/file/products/yure/penyou/2012-12-27/f49a9bae6700322893780ffb6604cb0f.jpg" height=310 width=228 border=2></span><img src="http://www.ymars.com.cn/d/file/products/houchuli/guolvqi/2012-12-27/a4563ebb4e6f17df77e71d5d1a68ae50.jpg" height=310 width=228 border=2>
<img src="http://www.ymars.com.cn/d/file/products/houchuli/xifu/2012-12-27/70d6040847d6c98377412667f99f1c47.jpg" height=310 width=228 border=2>
<img src="http://www.ymars.com.cn/d/file/products/houchuli/lengdong/2012-12-27/3864ddf6fec906b5d5d4e53445442499.jpg" height=310 width=228 border=2></span></p>
</td>
</tr>
</table>
</center>
</body>
</html>