如何将 html 表转换为 JSON 字符串。
示例:
<table cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td>Car</td>
<td>Year</td>
</tr>
<tr>
<td>Nissan</td>
<td>2009</td>
</tr>
<tr>
<td>Chrysler</td>
<td>2004</td>
</tr>
</tbody>
</table>
类似于:$('table tr').toJSON
打印出td
的所有值
最佳答案
试试这个
var rowList = new Array();
$("table tr").each(function () {
var colList = new Array();
$("td", this).each(function () {
colList.push($(this).text());
});
rowList.push(colList);
});
rowList
是 td 中所有值的二维列表
关于jquery - 在 jquery 中将 HTML 表转换为 JSON,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10796904/