标签:全局 var url new 否则 service href 链接 a标签
html部分
<a href="" id="pta"><div id="picture" class="pt"></div></a>a标签包裹着div,背景图片作为链接
script部分
var n=-1;//n作为全局变量放在外面,否则每次刷新n的值都是-1
function pt(){
var tp=new Array(‘url(../bank/picture/1111.jpg)‘,‘url(../bank/picture/2222.jpg)‘,‘url(../bank/picture/3333.jpg)‘,‘url(../bank/picture/4444.jpg)‘)
var adiv=new Array(‘http://www.bankofchina.com/pbservice/bi3/201701/t20170124_8524721.html‘,‘http://www.bankofchina.com/pbservice/pb7/‘,‘http://www.bankofchina.com/pbservice/pb8/‘,‘http://www.bankofchina.com/cbservice/cb11/‘)
var picture=document.getElementById(‘picture‘)
var pta=document.getElementById(‘pta‘)
n+=1
e=n%tp.length;
pta.setAttribute(‘href‘,adiv[e])
picture.style.background=tp[e]
setTimeout(‘pt()‘,3000)
}
pt()
标签:全局 var url new 否则 service href 链接 a标签
原文地址:http://www.cnblogs.com/webwangjie/p/6687099.html