从了解document.getElementById
和开始setInterval
。
http://jsfiddle.net/wtNhf/
HTML:
<span id="fruit"></span>
Javascript:
var title = ['Orange', 'Apple', 'Mango', 'Airplane', 'Kiwi'];
var i = 0; // the index of the current item to show
setInterval(function() { // setInterval makes it run repeatedly
document
.getElementById('fruit')
.innerHTML = title[i++]; // get the item and increment i to move to the next
if (i == title.length) i = 0; // reset to first element if you've reached the end
}, 1000); // 1000 milliseconds == 1 second