我怎样才能拥有它,以便每次单击按钮时数组都迭代一次?如果我再次单击它,它应该显示第二个数组元素等,直到它遍历整个数组。
JavaScript:
var images = [
"<img src='first.png' />",
"<img src='second.png' />",
"<img src='third.png' />",
"<img src='kitten.png' />"
];
var button = document.getElementsByClassName("btn-lg")[0];
button.addEventListener("click", function(){
for(i = 0; i < 5; i++) {
jQuery('.row.text-center').append(images[i]);
}
});
HTML:
<div class="row text-center">
<button type="submit" class="btn btn-lg btn-info">Click Here!</button>
</div>
jsfiddle:http: //jsfiddle.net/KVs6S/1/
谢谢!