作者fr730149 ()
看板Ajax
標題Re: [問題] JQuery合併td
時間Fri Sep 23 11:08:03 2011
抱歉!以下程式碼,有幾行不懂
煩請前輩們指教
: : // 從第一個row逆向走訪每一個cell
: : $($('tr:first td').get().reverse()).each(function(index){
: : // $start為比對目標,指向每一組的首項cell
: : var $start = $current = $(this);
: : var $next;
: : var need_remove = $([]);
: : // 逆向所以index要算一下
: : index = $start.parent().children().length - index - 1;
: : // 取得同一個column的下一個cell
就我所知,while()內應該是放判斷條件
而在此處是放($next=$current.parent().next().children().eq(index)).length…
這是什麼意思…?
: : while(($next=$current.parent().next().children().eq(index)).length){
: : if($start.html() == $next.html()){
就我所瞭解,parseInt()是轉換數字
在其後面加上 || 1 ,是轉換失敗時…將其設為1嗎?
: : var rs = (parseInt($start.attr('rowspan'), 10) || 1) + 1;
: : $start.attr('rowspan', rs);
: : need_remove.push($next);
: : }
: : else{
: : $start = $next;
: : }
: : $current = $next;
: : }
: : // 每跑完一個column才移除不要的cell
: : need_remove.each(function(){
: : this.remove();
: : });
: : });
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.125.235.184
推 No:啊..這些是我偷懶的寫法.. 括號內是為了讓assignment先完成 09/23 13:34
→ No:接著可以看作 ($next).length 這邊會這樣寫是因為 09/23 13:35
→ No:jQuery object若沒有選到element,它的length值就會是 0 09/23 13:35
→ No:否則就是大於0的數值,因此可以利用它自動casting來做條件判斷 09/23 13:37
→ No:第二個問題,你理解的沒錯,比較詳細的解釋 09/23 13:38
→ fr730149:原來while還可以這樣用 長見識了 謝謝 09/23 14:41