怎么个欸两个function合并成一个var imgs = ['1.jpg', '2.jpg','3.jpg'];// 显示图片的数量var imgCount = 1;var index = 0;function rightClick(){ index -= imgCount; if(index < 0) { index = 0; return; } document.getElementById("img1").setAttribute('src', imgs[(index)%3]); document.getElementById("img2").setAttribute('src', imgs[(index + 1)%3]); document.getElementById("img3").setAttribute('src', imgs[(index+2)%3]);}function leftClick(){ index += imgCount; if(index > imgs.length){ index = imgs.length; return; } document.getElementById("img1").setAttribute('src', imgs[(index)%3]); document.getElementById("img2").setAttribute('src', imgs[(index +1)%3]); document.getElementById("img3").setAttribute('src', imgs[(index+2)%3]); }
1 回答
MM们
TA贡献1886条经验 获得超2个赞
var imgs = ['1.jpg', '2.jpg','3.jpg'];
// 显示图片的数量
var index = 0;
function keyClick(setT){//setT=1或者-1
index += setT;
if(index < 0){
index = 0;
}
if(index > imgs.length){
index = imgs.length;
}
document.getElementById("img1").setAttribute('src', imgs[(index)%3]);
document.getElementById("img2").setAttribute('src', imgs[(index +1)%3]);
document.getElementById("img3").setAttribute('src', imgs[(index+2)%3]);
}
添加回答
举报
0/150
提交
取消