[英]loop html table using jquery and for loop (not for each)
我有一个HTML表
<table id="mytab">
<thead>
<th>col1</th>
<th>col2</th>
</thead>
<tbody>
<tr>
<td>1</td>
<td>2</td>
</tr>
<tr>
<td>11</td>
<td>22</td>
</tbody>
</table>
我正在编写jquery函数
function LoopTable()
{
$row = $('#mytab tbody >tr"); //here I have successfully find all the rows.
//now i want to loop on rows and find each column row
for (var i=0; i<$rows.length; i++)
{
//need something here to find col data
}
我应该用什么来从行中获取列值
更新的代码
$(document).ready(function() {
var rows = $('#mytab tbody >tr');
var columns;
for (var i = 0; i < rows.length; i++) {
columns = $(rows[i]).find('td');
for (var j = 0; j < columns.length; j++) {
console.log($(columns[j]).html());
}
}
});
for (var i=0; i<$rows.length; i++)
{
$.each($row[i].children("td"), function(key, value) {
console.log(value);
});
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.