好吧,我有一個函數可以獲取藤的推文,然後通過iFrame顯示視頻。這很好,唯一的問題是我不想一次列出它們,我只想要一個顯示,然後一旦完成顯示下一個。這可能很簡單,但我一直在看代碼很久,現在我無法思考。請幫忙。通過使用.each()的JQuery循環輸出緩衝區()
function getTweets() {
var url='http://search.twitter.com/search.json?callback=?&q=givingvine';
$.getJSON(url,function(json){
//setup an array to buffer output
var output = [];
//a for loop will perform faster when setup like this
for (var i = 0, len = json.results.length; i < len; i++) {
//instead of appending each result, add each to the buffer array
output.push('<p>' + '<iframe class="video" src="' + json.results[i].text.substr(json.results[i].text.indexOf("http")) +'" frameborder="0" width="1080" height="800" style="margin:-155px -100px -130px -60px;"></iframe>' + '</p>');
}
//now select the #results element only once and append all the output at once, then slide it into view
$.each(output, function (intIndex, objValue) {
$("#results").html(objValue);
});
});
}
//set an interval to run the getTweets function (30,000 ms is 5 minutes), you can cancel the interval by calling clearInterval(timer);
var timer = setInterval(getTweets, 10000);
clearInterval(timer);
//run the getTweets function on document.ready
getTweets();
});
這是有點我在找什麼,我不想要一個按鈕,我希望它切換後的指定ic間隔 – Christopher 2013-03-01 17:07:09
然後用window.setInterval(function(){//從上面的代碼點擊函數}中取代「click」函數},10000); // 10秒間隔應該存儲在一個變量中,以便在達到項目長度時可以將其刪除。 – TommyBs 2013-03-01 17:08:10