jQuery遍历td获取到td的Html值,包括标签和属性
jquery获取到table下的所有td,遍历td的时候获取td的html()只能获取到td里面的具体值,不能获取到td标签和属性,后续的操作需要用到这些数据,该如何获取?
例如:
<table>
<tr>
<td class="s1">查询1</td>
</tr>
</table>
只能获取到查询1",需要获取"<td class='s1'>查询1</td>"
以下两种回答,不同场景请对号入座
答案1:
1 | $( 'table tr' ).each( function (){ |
2 | console.log($( this ).html()) |
3 | }) |
1 | $( 'table' ).find( 'td' ).each( function (){ |
2 | console.log( this .outerHTML) |
3 | }) |
原文链接:jQuery遍历td获取到td的Html值,包括标签和属性