0
我有2個按鈕。每個按鈕都顯示不同的數組。一切都很好,除非我想回到第一次重新加載圖像。所以當我第一次點擊按鈕時,我的6張圖片就出現了。第二次是12.等等。有沒有辦法阻止這種情況發生?似乎無法在網上找到任何東西。使用JavaScript,如何停止圖像重新加載?
var picArray1 = new Array("concert1","concert2","concert3","concert4","concert5","concert6");
var picArray2 = new Array("out1","out2","out3","out4","out5","out6");
function showArray1() {
var imgDiv = document.getElementById("gallery")
for(i=0; i<picArray1.length; i++){
document.getElementById("text1").innerHTML += '<img src="images/'+picArray1[i]+'.jpg">';
document.getElementById("text2").style.display = 'none';
document.getElementById("text1").style.display = 'block';
}
}
function showArray2() {
var imgDiv = document.getElementById("gallery")
for(i=0; i<picArray2.length; i++){
document.getElementById("text2").innerHTML += '<img src="images/'+picArray2[i]+'.jpg">';
document.getElementById("text1").style.display = 'none';
document.getElementById("text2").style.display = 'block';
}
}