2016-04-07 27 views
0

Tablo satırlarını php olarak basan bir SQL ifadem var, 1 satır olabilir veya 10 satır olabilir. Her satırda bir tarihçeri vardır ve tarihçer her satırda kendi başına çalışır. Ancak, yeni satır eklemek için satırın sonundaki + simgesine tıkladığımda tarihçenin görünmez olması. Daha önceki satır ile aynı kimliği ataıyor gibi görünüyor.Datepicker Clone ID Satır Ekleme Satır Ekle

JavaScript: İşte benim kodudur

$(window).on('load', function() { 
    $(document).ready(function() { 

     $(document).on('click', '#purchaseItems .add', function() { 
      var row = $(this).closest('tr'); 
      var clone = row.clone(); 

      // clear the values 
      var tr = clone.closest('tr'); 
      tr.find('input[type=text]').val(''); 

      $(this).closest('tr').after(clone); 
     }); 

     $(document).on('keypress', '#purchaseItems .next', function (e) { 
      if (e.which == 13) { 
       var v = $(this).index('input:text'); 
       var n = v + 1; 
       $('input:text').eq(n).focus(); 
       //$(this).next().focus(); 
      } 
     }); 
     $(document).on('keypress', '#purchaseItems .nextRow', function (e) { 
      if (e.which == 13) { 
       $(this).closest('tr').find('.add').trigger('click'); 
       $(this).closest('tr').next().find('input:first').focus(); 
      } 
     }); 
     $(document).on('click', '#purchaseItems .removeRow', function() { 
      if ($('#purchaseItems .add').length > 1) { 
       $(this).closest('tr').remove(); 
      } 
     }); 

     $('.datepicker').each(function() { 
      $(this).removeClass('hasDatepicker').datepicker(); 
     }); 
    }); 
}); 

Tablo:

<table id="purchaseItems" name="purchaseItems" class="table table-striped table-condensed"> 
    <tr> 
     <th>Date</th> 
     <th>Billable</th> 
     <th>Client</th> 
     <th>Details</th> 
     <th></th> 
     <th></th> 
    </tr> 
    <tr> 
     <td><input class='datepicker' name='from[]' value='$date' size='12'/></td> 
     <td> 
      <select name='billable[]'> 
       <option value='$billable' selected>$billable</option> 
       <option value='No'>No</option> 
       <option value='Yes'>Yes</option> 
      </select> 
     </td> 
     <td><input type='text' name='client[]' value='$client' size='10'></td> 
     <td><input type='text' value='$details' name='details[]' size='10'></td> 
     <td><input type='button' name='addRow[]' class='add' value='+' /></td> 
     <td><input type='button' name='addRow[]' class='removeRow' value='-' /></td> 
    </tr> 
</table> 

Yani, ince satır eklemek ince satırları silmek, şu anda tarih dahil satırları değiştirebilir. Sorun, + düğmesine bastığımda satırı ekler, ancak datepicker açılır.

Sadece klonlama ile ilgili olduğunu biliyorum, bu yüzden klon satırındaki kimliği değiştirmek için doğru yönde bir noktaya ihtiyacım var.

cevap

0

bunu çözüldü: Eğer olsa ona bir göz olsaydı

$(".datepicker").datepicker(); 

    $(document).on('click', '#purchaseItems .add', function() { 



    $(".datepicker").datepicker("destroy"); 

    $(".datepicker").removeClass("hasDatepicker").removeAttr('id'); 


    var row = $(this).closest('tr'); 
    var clone = row.clone(); 



    // clear the values 
    var tr = clone.closest('tr'); 
    tr.find('input[type=text]').val(''); 

    $(this).closest('tr').after(clone); 

    $(".datepicker").datepicker(); 

}); 

teşekkür ederiz.