我想获取每个行的Date1 Date2 Date3 Date4的值,所以行将等于数组[], ,行[0]将是[3 ,3,4,6]和行[1]是[93.9,99,98.9,99] ...使用jquery在html中从表中获取值
看到JS小提琴这里 http://jsfiddle.net/HLhT4/1/
$(function() {
var $table = $("#work_table"),
$headerCells = $table.find("th"),
$rows = $table.find("tr tr");
var headers = [],
rows = [];
$headerCells.each(function(k,v) {
headers[headers.length] = $(this).text();
});
$rows.each(function(row,v) {
$(this).find("td").each(function(cell,v) {
if (typeof rows[cell] === 'undefined') rows[cell] = [];
rows[cell][row] = $(this).text();
});
});
console.log(headers);
//console.log(rows);
alert(headers);
alert(rows);
});
我已经有头部。
注意:也许我需要更改类和id属性。
这似乎是不对的:$ rows = $ table.find(“tr tr”); –
你确定选择器'tr tr'吗?这在行内查找行。 – Barmar
为什么是嵌套行。如果是这样的话,认为表格是畸形的。 – Sukima