在不使用 jQuery 的情况下在 JavaScript 中将表转换为数组 [英] Convert table to array in JavaScript without using jQuery
本文介绍了在不使用 jQuery 的情况下在 JavaScript 中将表转换为数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要根据表格内部的内容将我创建的表格网格转换为多维数组.数组的格式如下:
I need to convert the table grid i created into an multidimensional array according to the content inside the table. Array would be in format like:
var array = [
[column,column,...],
[column,column,...],
...
];
如何在不使用 jQuery 的情况下使用纯 JavaScript 执行此操作?我找到的所有答案都在 jQuery 中.
How do I do this without using jQuery, using plain JavaScript? All answers I found was in jQuery.
推荐答案
使用 qSA 和 Array.prototype.map
非常简单.
With qSA and Array.prototype.map
is pretty simple.
var tableInfo = Array.prototype.map.call(document.querySelectorAll('#tableId tr'), function(tr){
return Array.prototype.map.call(tr.querySelectorAll('td'), function(td){
return td.innerHTML;
});
});
这篇关于在不使用 jQuery 的情况下在 JavaScript 中将表转换为数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文