use*_*790 3 html jquery json html-table
我遇到了一个必须将HTML表格数据转换为JSON的情况.在这个过程中,我必须遍历表并逐个(行)转换为数组,然后将整个数组转换为JSON.如何遍历表(每行和每列)?
首先,fredrik指出我们需要包括https://github.com/douglascrockford/JSON-js.
其次,我们可以使用jQuery.fn.map和jQuery.fn.get来创建一个数组数组(tr:s),其中包含元素的jQuery.fn.text内容td:
var AoA = $('table tr').map(function(){
return [
$('td',this).map(function(){
return $(this).text();
}).get()
];
}).get();
var json = JSON.stringify(AoA);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10198 次 |
| 最近记录: |