标签:javascript
<script type="text/javascript">
//第一种方法,使用数组
var i=0;
function t1(){
var arr=[‘url(img/bgf.jpg)‘,‘url(img/bg.jpg)‘,‘url(img/4f.jpg)‘,‘url(img/5f.jpg)‘,‘url(img/6f.jpg)‘];
var bottom = document.getElementById(‘zhengti‘);
if(i==arr.length){
i=0;
}
bottom.style.backgroundImage = (arr[i++]);
}
/*第二种方法,if...else判断
var i = 0;
function t1(){
var bottom = document.getElementById(‘zhengti‘);
if(i++%2==0){
bottom.style.backgroundImage = "url(img/bgf.jpg)";
}
else{
bottom.style.backgroundImage = "url(img/bg.jpg)";
}
}
*/
</script>
</head>
<body id="zhengti">
<div id="bottom">
<input type="button" value="更换背景" onclick="t1();" />
</div>
</body>
</html>本文出自 “hbbdgyb” 博客,请务必保留此出处http://hbbdgyb.blog.51cto.com/5031387/1844851
标签:javascript
原文地址:http://hbbdgyb.blog.51cto.com/5031387/1844851