Re: [問題] jQuery each --> Native Loop
※ 引述《DRLai (蘇打)》之銘言:
: <script>
: $(document).ready(function(){
: $("#test").children("div").each(function(){
: $("#debug").append("I got "+$(this).attr("id")+"<br/>");
: });
: });
如果 #test 下面很多 div,要快的話就是先累積再一次插入:
$(function(){
var t = '';
$('#test > div').each(function(){
t += 'I got ' + $(this).attr('id') + '<br/>';
});
$('#debug').append(t);
});
這樣可以節省 browser redraw 時間。
另外還有 string concat 的問題 (不知道現在新的 browser 還需不需要在意這個),
可以用 array + join 處理:
$(function(){
var t = [];
$('#test > div').each(function(){
t.push('I got ' + $(this).attr('id') + '<br/>');
});
$('#debug').append(t.join(''));
});
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 210.242.135.97
※ 編輯: DarkKiller 來自: 210.242.135.97 (08/06 00:14)
→
08/06 08:22, , 1F
08/06 08:22, 1F
→
08/06 08:22, , 2F
08/06 08:22, 2F
→
08/06 08:23, , 3F
08/06 08:23, 3F
→
08/06 08:23, , 4F
08/06 08:23, 4F
推
08/06 09:04, , 5F
08/06 09:04, 5F
→
08/06 09:05, , 6F
08/06 09:05, 6F
→
08/06 09:06, , 7F
08/06 09:06, 7F
→
08/06 09:07, , 8F
08/06 09:07, 8F
→
08/06 15:27, , 9F
08/06 15:27, 9F
→
08/06 15:27, , 10F
08/06 15:27, 10F
→
08/06 15:28, , 11F
08/06 15:28, 11F
推
08/07 12:09, , 12F
08/07 12:09, 12F
→
08/07 12:09, , 13F
08/07 12:09, 13F
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 3 之 3 篇):