循环的HTML表使用jQuery和for循环(不是每个) [英] loop html table using jquery and for loop (not for each)
本文介绍了循环的HTML表使用jQuery和for循环(不是每个)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个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函数
函数LoopTable()
{
$ row = $('#mytab tbody> tr); //这里我已经成功找到所有行。 b
$ b //现在我想循环行并找到每个列行
for(var i = 0; i< $ rows.length; i ++)
{
//需要在这里找到col数据
}
我应该用于从行获得列值
解决方案
更新后的代码
<$ p $ ($)$($#$ var行)$ $ $ $ (var i = 0; i
for(var j = 0; j< ; column.length; j ++){
console.log($(columns [j])。html());
}
}
});
I have a HTML table
<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>
and i am writing the jquery function
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
}
what I should use to have column values from row
解决方案
Updated code
$(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());
}
}
});
这篇关于循环的HTML表使用jQuery和for循环(不是每个)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文