2014-04-09 42 views
0

我已經使用jQuery的多行。目前,當我點擊「添加新的」按鈕時,在當前行和按鈕名稱下方添加的行更改爲「刪除」。但我需要改變過程如下: 當我點擊「添加新的」按鈕,當前行上方添加的行和按鈕名稱更改爲「刪除」。 我需要顯示「添加新的」按鈕到最後一行,以前的行必須有「刪除」按鈕。我不會在上面添加行。如果有人知道,請幫助我。jquery多行更改「添加新」到「刪除」位置

這裏是檢查 http://jsfiddle.net/tWada/

$("input[type='button'].AddRow").live('click', 
function() { 
    var index = $(this).closest('tr').index(); 
    if (index > 0) { 
     $(this).closest('tr').remove(); 

    } else { 


     var $tr = $(this).closest('tr').clone(true); 
     $tr.find('img').remove(); 
     var $input = $tr.find('input.startdatum'); 
     var index = $('input#counter').val(); 
     $('#acti_btn').val('Delete'); 
     var id = 'datepicker' + index; 
     index++; 

     $('input#counter').val(index); 
     $input.attr('id', id).data('index', index); 
     console.log(index); 
     $tr.prependTo($(this).closest('table'));  

    } 

回答

0

我現在得到了解決方案。我曾嘗試使用下面的代碼

$tr.find('.AddRow').val('Delete')// set value to Delet 
      .toggleClass('AddRow delete')// toggle classes 
      .unbind('click'); // unbind the current events from button 

,而不是

$( '#acti_btn')VAL( '刪除')。

0

嘗試的insertBefore(),如提及以下

$tr.insertBefore($(this).closest('table')); 

,你可能還需要作出一些的insertBefore名changes.Docs()是here小提琴希望有幫助。

+0

謝謝aameer。我還有一個疑問。如果我將「prependto」更改爲「insertbefore」,則新行將被添加到當前行的上方。但新添加的行顯示爲未對齊,並且當前行按鈕將被更改爲刪除。我們如何糾正?這裏是改變小提琴http://jsfiddle.net/tWada/1/ – NitheesBavesh

+0

自己嘗試一下,如果你不能,我會在晚上檢查它 – Aameer

+0

我嘗試它。但我無法得到它。我不熟悉jquery。請工作我解決這個問題。 – NitheesBavesh