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

160
Views
Cómo obtener el valor de la fila anterior en la cuadrícula HTML usando JQuery/Javascript

Cómo obtener el valor de la columna anterior en la cuadrícula usando Javascript/JQuery.

Los campos A, B y C siempre ingresan valores de campo (cuadro de texto). En la primera fila, los valores D,E,F siempre serán "NA" y en la segunda fila en adelante, el valor de D,E,F debe ser el valor de la fila anterior de A,B,C como se indica a continuación. Cómo obtener el valor de las columnas anteriores usando jQuery.

 ABCDEF -------------------- 10 20 30 NA NA NA Edit 40 50 70 10 20 30 Edit 66 27 38 40 50 70 Edit

Según mi código a continuación, obtengo el resultado de la fila anterior. Pero supongamos que cuando hago clic en Editar en la segunda fila, está leyendo los valores de columna actuales de A, B, C. Debería leer los valores de columna anteriores de A,B,C. Tengo campos HTML para hacer la grilla.

 var xyz=0 $("tbody").find("tr").each(function () { var val = $(this).find('td.tdColumnofAText').text(); if ($(this).find('td.tdColumnofAText').text() > 0) { xyz = Number(val); } }); $('#txtofDValue').val(xyz);

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Considera lo siguiente.

 $(function() { function initTable(table) { var cur; var next; $("tbody tr", table).each(function(index, elem) { cur = [ $("td:eq(0)", this).text().trim(), $("td:eq(1)", this).text().trim(), $("td:eq(2)", this).text().trim() ]; next = $(this).next(); if (next !== undefined) { $("td:eq(3)", next).html(cur[0]); $("td:eq(4)", next).html(cur[1]); $("td:eq(5)", next).html(cur[2]); } }); } initTable($("table")); });
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <table> <thead> <tr> <th>A</th> <th>B</th> <th>C</th> <th>D</th> <th>E</th> <th>F</th> <td>&nbsp;</td> </tr> <thead> <tbody> <tr> <td>10</td> <td>20</td> <td>30</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>Edit</td> </tr> <tr> <td>40</td> <td>50</td> <td>70</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>Edit</td> </tr> <tr> <td>66</td> <td>27</td> <td>38</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>Edit</td> </tr> </tbody> </table>

Esto recorre cada fila y recopila algunos valores. Luego lo agrega a celdas específicas en la fila Siguiente, si existe.

about 4 years ago · Juan Pablo Isaza Report
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!