Re: [問題] jQuery each --> Native Loop
※ 引述《DRLai (蘇打)》之銘言:
: 最近在撰寫一個網頁
: 由於網頁中會動態產生大量表格資料
: 導致網頁會慢一些
: 翻了一下網路上關於 jQuery performance 的文章
: 看到把.each改用 javascript native loop 會快很多
: 嘗試修改卻改不出來
: 希望各位高手協助一下
: 簡單的程式碼如下
: <html>
: <head>
: <script type="text/javascript" src="jquery.js"></script>
: </head>
: <body>
: <div id="test">
: <div id="a1"></div>
: <div id="a2"></div>
: </div>
: <div id="debug"></div>
: <script>
: $(document).ready(function(){
: $("#test").children("div").each(function(){
: $("#debug").append("I got "+$(this).attr("id")+"<br/>");
: });
: });
: </script>
: </body>
: </html>
: 程式會取得 DIV#test 接著把他底下的 DIV id列印出來
: 想把 $("#test").children("div").each 換掉改用for
: 這樣有辦法嗎?
: 感謝m(_ _)m
我是不覺得這樣會有很明顯的改善啦,不過要換的話也不難
: $("#test").children("div").each(function(){
: $("#debug").append("I got "+$(this).attr("id")+"<br/>");
: });
改
var item = $("#test").children("div"),dbg = $("#debug");
for(var i = 0,len = item.length;i < len ;++i){
dbg.append("I got "+ item.eq(i).attr("id")+"<br/>");
}
大約是這樣,順手打得可能有些typo 但應該相去不遠。
--
網頁上拉近距離的幫手 實現 GMail豐富應用的功臣
數也數不清的友善使用者體驗 這就是javascript
歡迎同好到 AJAX 板一同討論。
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 1.34.116.11
推
08/01 00:46, , 1F
08/01 00:46, 1F
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 2 之 3 篇):