首先获取元素ID赋值给变量,然后对变量添加点击事件,以下是没有运用数组的情况
<script>
/*图片轮番*/
window.onload=function(){
var pre=document.getElementById("pre");
var next=document.getElementById("next");
var pic=document.getElementById("pic");
n=5;
next.onclick=function(){
n=n+1;
if(n>7){
n=5;
}
pic.src='{global.cfg_cmspath/}/templets/hx/images/'+n+'.png';
}
pre.onclick=function(){
n--;
if(n<5){
n=7;
}
pic.src='{global.cfg_cmspath/}/templets/hx/images/'+n+'.png';
}
}
</script>