访问带索引的表tr(access to a table tr with index)
我想在表格中获得一行内容:
<div class="myTable"> <table id="dataTable"> <tbody> <tr> <td>First</td> </tr> <tr> <td>second</td> </tr> </tbody> </table> </div>为了获得我使用的td:
$('#dataTable').find('tbody').find('tr:nth-child(1)');工作并得到tr数据,但是,什么时候用变量:
var j= 1; $('#dataTable').find('tbody').find('tr:nth-child(j)');它失败。
问题是什么?
I want to get a row content in my table:
<div class="myTable"> <table id="dataTable"> <tbody> <tr> <td>First</td> </tr> <tr> <td>second</td> </tr> </tbody> </table> </div>To get the td I use:
$('#dataTable').find('tbody').find('tr:nth-child(1)');wich works and get the tr data, but, when do it with variable:
var j= 1; $('#dataTable').find('tbody').find('tr:nth-child(j)');it fails.
What is the problem?
最满意答案
var j= 1; $('#dataTable').find('tbody').find('tr:nth-child(' + j +')'); var j= 1; $('#dataTable').find('tbody').find('tr:nth-child(' + j +')');更多推荐
发布评论