2016-12-16 21 views
0

我有這個表格佈局移動<TD類=「45記錄」>到最後的以前<tr>

enter image description here

我試圖移動數量字段上的一行- fullfit(如45 fullfit)比前行的上方,被定位到最後一列..

這裏的HTML代碼

enter image description here

這裏是我的部分代碼

jQuery("tr").each(function(index, el) { 
    var tdfull = jQuery("[class$='-fullfit']"); //successful on finding <td>'s with "-fullfit" suffixes 
    jQuery(this).prev("tr").append(tdfull); //adds all the <td>'s on the last row 
}) 

這應該是結果

enter image description here

+0

看到我的回答波紋管 – madalinivascu

回答

1

你可以試試下面的循環:

$('[class$="fullfit"]').each(function(){ 
var el = $(this).closest('tr').prev();//go to the parent tr get the previous tr 
el.append($(this));//append the current element to the tr 
}); 

演示:

$('[class$="fullfit"]').each(function() { 
 
    var el = $(this).closest('tr').prev(); 
 
    $(this).closest('tr').remove(); 
 
    el.append($(this)); 
 
    
 
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<table> 
 
    <tr> 
 
    <td>5'5''-5'2'</td> 
 
    <td>45</td> 
 
    <td class="45"> 
 
     <input type="text"> 
 
    </td> 
 
    </tr> 
 
    <tr> 
 
    <td>5'5''-5'2'</td> 
 
    <td>45 fullfit</td> 
 
    <td class="45-fullfit"> 
 
     <input type="text"> 
 
    </td> 
 
    </tr> 
 
    <tr> 
 
    <td>5'5''-5'2'</td> 
 
    <td>45</td> 
 
    <td class="45"> 
 
     <input type="text"> 
 
    </td> 
 
    </tr> 
 
    <tr> 
 
    <td>5'5''-5'2'</td> 
 
    <td>45 fullfit</td> 
 
    <td class="45-fullfit"> 
 
     <input type="text"> 
 
    </td> 
 
    </tr> 
 
</table>

+0

謝謝你..你能刪除行與fullfit? –

+0

它刪除數量字段和混亂的佈局.. –

+0

看到我更新的代碼段 – madalinivascu

相關問題