Re: [問題] JQuery合併td

看板Ajax作者時間14年前 (2011/11/02 19:44), 編輯推噓1(101)
留言2則, 1人參與, 最新討論串9/10 (看更多)
拜版上前輩所賜,得到合併欄位解。 但如今,只想把非數字的欄位做合併,但怎樣也寫不出來: 目前我的作法: 將欄位為數字的cell,給定一css class name:Number_Right, 然後將No前輩所給的解,改成以下: $($('tr:first td:not(:contains('Number_Right'))').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){ : if($start.html() == $next.html()){ : 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: 58.99.73.60 ※ 編輯: fr730149 來自: 58.99.73.60 (11/02 19:46)

11/02 23:12, , 1F
你看要不要試著用原本的code,然後在
11/02 23:12, 1F

11/02 23:12, , 2F
if($start.html() == $next.html()) 改這邊的判斷就好
11/02 23:12, 2F
文章代碼(AID): #1EiIqNQ6 (Ajax)
討論串 (同標題文章)
文章代碼(AID): #1EiIqNQ6 (Ajax)