HTML code
//从数据库中获取相应src 图片路径
var array = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10'];
window.onload = function() {
document.getElementById('div').innerHTML = array[0];
setTimeout(function() { change(1); }, 1000); //1000 是 1秒,这里是为了看到效果
}
function change(i) {
if (i == array.length) {
i = 0;
}
document.getElementById('div').innerHTML = array[i];
setTimeout(function() { change(i + 1); }, 1000);
}
------解决方案--------------------探讨
HTML code
//从数据库中获取相应src 图片路径
var array = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10'];
window.onload = function() {
document.getElementById('div').innerHTML = array[0];
setTimeout(function() { change(1); }, 1000); //1000 是 1秒,这里是为了看到效果
}
function change(i) {
if (i == array.length) {
i = 0;
}
document.getElementById('div').innerHTML = array[i];
setTimeout(function() { change(i + 1); }, 1000);
}