看板 Ajax 關於我們 聯絡資訊
感謝你的指導,的確是忽略效率的問題。 附帶一提,下方語法少了一個 ) : $("th").each(function(){ : var $this = $(this); if(!($this.contains("男人數")||$this.contains("女人數"))){ : $this.attr("rowSpan", 2); : } : }); 執行後firebug報錯: $this.contains is not a function 請問這要怎麼解決呢? : 降寫不是輕鬆多了嗎 = = a : 如果能改html,那就乾脆把需要上rowSpan 的或者不上rowSpan 的, : 給個特定的class或attribute 直接用class或attribute來濾。 : 不要浪費時間再寫一個很複雜很「豐富」的selector, : 一是越複雜的selector 越慢,二是讀起來越痛苦。 : 另外沒有必要的話不要針對 "th" 這種大範圍兵器操作, : 小心以後改版需要增加table或者殺到自己畫面上沒必要的人。 : 幫table上個 id ex."userTable" , : 再操作 $("#userTable th") 效率也會好一點,風險也可以降低。 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.125.235.184
Fantasywind:http://api.jquery.com/jQuery.contains/ 用法錯誤 09/17 00:43