Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

238
Views
Calcule la fecha de la fila según la fila anterior en la tabla

Tengo esta tabla dinámica. Agregar más botón agregar una nueva fila. La fila consta de número o días y campo de fecha. Significa cuántos días se agregaron los resultados en la fecha.

Ahora en la segunda fila, si agrego un número de días; debe comprobar la fecha o el número de la fila anterior anterior y dar como resultado la fecha. Pero rowSelected.prev('tr')[0] no me da ningún valor.

¿Puede alguien por favor ayudarme?

 $(function() { $("#add-more").click(function() { $("#main-table").each(function() { let tds = '<tr>'; jQuery.each($('tr:last td', this), function() { tds += '<td>' + $(this).html() + '</td>'; }); tds += '</tr>'; if ($('tbody', this).length > 0) { $('tbody', this).append(tds); } else { $(this).append(tds); } }); }); $(document).on('change', '.total-days', function(e) { let rowSelected = $(this).closest('tr'); const someDate = new Date(); someDate.setDate(someDate.getDate() + parseInt($(this).val())); const newDate = someDate.toISOString().substr(0, 10); rowSelected.find('.expected-delivery-date').val(newDate); }); });
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script> <div class="col-sm-6 right"> <a class="inline btn btn-primary" id="add-more">Add More</a> </div> <table class="table table-bordered" id="main-table" border="1"> <thead> <tr> <th>No.</th> <th>From</td> <th>Expected Delivery Date</td> </tr> </thead> <tbody id="rows"> <tr> <td><input class="form-control" type="text" name="deliverableNumber[]" /></td> <td><input class="form-control total-days" type="number" value="1" name="deliverableNumberOfDays[]" /></td> <td> <input class="form-control expected-delivery-date" type="date" name="deliverableExpectedDeliveryDate[]" /> </td> <td><i class="fa-2x fa fa-trash" onclick="SomeDeleteRowFunction(this)" title="Remove row"></i></td> </tr> </tbody> </table>

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!