我有以下html:
<tbody id="rankwyz-blogs">
<tr role="row" class="odd">
<td>
<div class="checker"><span><input name="pid" type="checkbox" class="checkboxes" value="3350239"></span></div>
</td>
<td class="sorting_1">blog</td>
<td>
<a href="http://anonym.to/?http://jaysonlrrv.blog.com" target="_blank">http://jaysonlrrv.blog.com</a>
</td>
</tr>
<tr role="row" class="even">
<td>
<div class="checker"><span><input name="pid" type="checkbox" class="checkboxes" value="3350241"></span></div>
</td>
<td class="sorting_1">blog</td>
<td>
<a href="http://anonym.to/?http://dewaynecypn.blog.com" target="_blank">http://dewaynecypn.blog.com</a>
</td>
</tr>
</tbody>
我想写一个javascript / jQuery来提取第三个td的值。所以在这种情况下我希望输出为:
http://jaysonlrrv.blog.com
http://dewaynecypn.blog.com
最好和最有效的方法是什么?
答案 0 :(得分:1)
这并不困难。循环遍历tr
元素并获取第3列:
$(function () {
var urls = [];
$('#rankwyz-blogs tr').each(function () {
urls.push($(this).find('td').eq(2).text());
});
alert(urls);
});
答案 1 :(得分:1)
您可以使用JQuery执行此操作:
$(function(){
$('#rankwyz-blogs tr').each(function(i, tr){
console.log($(tr).find('td').eq(2).text());
});
});
答案 2 :(得分:0)
以下代码是最有效的方式:
$("#rankwyz-blogs tr").each(function(){
alert($(this).children("td").last().children("a").text());
});
<强>更新强>
您需要在<table>
之前添加<tbody>
,请查看此Fiddle ..