【发布时间】:2020-05-21 01:55:40
【问题描述】:
我有以下 HTML 代码:
<table id="resultados" class="table table-checkable dataTable no-footer ">
<tbody>
<tr id="Rhead">
<th style="background-color: rgb(27, 197, 189);">Código</th>
<th style="background-color: rgb(27, 197, 189);">Proveedor</th>
<th style="background-color: rgb(27, 197, 189);">Producto</th>
<th style="background-color: rgb(27, 197, 189);">Precio</th>
<th style="background-color: rgb(27, 197, 189);">Acciones</th>
<th style="background-color: rgb(27, 197, 189);">Cantidad</th>
</tr>
<tr id="N1row">
<td id="1menu">1</td>
<td id="1menu">1</td>
<td id="1menu">Ham Clasica</td>
<td id="1menu">3</td>
<td id="NCellRow1">
<center><button id="N1button" onclick="ResponseTableButton("N1row")" class="envio btn btn-link-success"><i class="glyphicon glyphicon-trash"></i></button></center>
</td>
<td id="1rowCellCantidad"><input type="text" id="N1rowInputCantidad" name="N1rowInputCantidad"></td>
</tr>
<tr id="N3row">
<td id="3menu">3</td>
<td id="3menu">1</td>
<td id="3menu">Ham Guayanesa</td>
<td id="3menu">4.5</td>
<td id="NCellRow3">
<center><button id="N3button" onclick="ResponseTableButton("N3row")" class="envio btn btn-link-success"><i class="glyphicon glyphicon-trash"></i></button></center>
</td>
<td id="3rowCellCantidad"><input type="text" id="N3rowInputCantidad" name="N3rowInputCantidad"></td>
</tr>
<tr id="N4row">
<td id="4menu">4</td>
<td id="4menu">1</td>
<td id="4menu">Ham New York</td>
<td id="4menu">5.6</td>
<td id="NCellRow4">
<center><button id="N4button" onclick="ResponseTableButton("N4row")" class="envio btn btn-link-success"><i class="glyphicon glyphicon-trash"></i></button></center>
</td>
<td id="4rowCellCantidad"><input type="text" id="N4rowInputCantidad" name="N4rowInputCantidad"></td>
</tr>
</tbody>
我需要获取每个单元格的每个值,甚至是表格中的输入表单值,并将其转换为格式化 json,但我找不到方法
这将是我需要的 json 格式:
[ "N1row"={ 'codigo': '1', 'Proveedor': '1', 'Producto': 'Ham Clasica', 'Precio': '3', 'Cantidad': '4', }, "N3row"={ 'codigo': '3', 'Proveedor': '1', 'Producto': 'Ham Guayanesa', 'Precio': '4.5', 'Cantidad': '5', }, "N4row"={ 'codigo': '4', 'Proveedor': '1', 'Producto': 'Ham New York', 'Precio': '5.6', 'Cantidad': '6', } ]
注意:所有行都是动态生成的,可以是N行
【问题讨论】:
标签: javascript html jquery html-table