<!DOCTYPE html>
<html lang="zh-cn">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<img src="images/1.png" alt="" id="imgid">
<script>
// 自动切换的广告图片
window.onload=rotate;
var Adimg=["images/1.png","images/2.png","images/3.png"];
var adimg=0;
function rotate(){
adimg++;
if(adimg==Adimg.length){
adimg=0;
}
document.getElementById('imgid').src=Adimg[adimg];
setTimeout(rotate,3000);
}
//显示随机图片
/*
window.onload=rotate;
function rotate(){
var Adimg=["images/1.png","images/2.png","images/3.png"];
var a=Math.floor((Math.random()*Adimg.length));
document.getElementById('imgid').src=Adimg[a];
}
*/
//单击图片切换
/*
var imgid=document.images['imgid'];
var ab=true;
imgid.onclick=function(){
if(ab){
imgid.src='images/2.png';
ab=false;
}else{
imgid.src='images/1.png';
ab=true;
}
}
*/
</script>
</body>
</html>
自动切换的广告图片
最新推荐文章于 2021-12-17 14:49:41 发布