<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>随机切换网页背景图片的JS代码</title>
</head>
<body>
<script language="javascript">
now = new Date();
erke = now.getSeconds();
erke = erke - parseInt(erke/3)*3 + 1;//定义张数
document.write("<div style='background:url(images/bg"+erke+".png) no-repeat;' id=Change></div>")
</script>
<!--这里放背景上面的内容-->
<div id=Change>
</div>
<style type="text/css">
<!--
body {margin: 0px;}
-->
</style>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>随机切换网页背景图片的JS代码</title>
</head>
<body>
<script language="javascript">
now = new Date();
erke = now.getSeconds();
erke = erke - parseInt(erke/3)*3 + 1;//定义张数
document.write("<div style='background:url(images/bg"+erke+".png) no-repeat;' id=Change></div>")
</script>
<!--这里放背景上面的内容-->
<div id=Change>
</div>
<style type="text/css">
<!--
body {margin: 0px;}
-->
</style>
</body>
</html>
本文介绍了一种使用JavaScript实现的网页背景图片随机切换的方法。通过获取当前时间的秒数来决定显示哪一张背景图片,实现了背景图片的定时轮换效果。
479

被折叠的 条评论
为什么被折叠?



