我在活动选项卡中有一个页面。 我需要在这个页面查找表:Chrome扩展程序:如何在页面上获取html的一部分?
<table width="100%" cellspacing="0" cellpadding="0" border="0" class="details">
抓住它,直到下一个</table>
- 标签, 并使用它(将其粘贴在一个新的标签,弹出,或者只是在“警报”)。
我在活动选项卡中有一个页面。 我需要在这个页面查找表:Chrome扩展程序:如何在页面上获取html的一部分?
<table width="100%" cellspacing="0" cellpadding="0" border="0" class="details">
抓住它,直到下一个</table>
- 标签, 并使用它(将其粘贴在一个新的标签,弹出,或者只是在“警报”)。
我不会包含这样一个简单的任务jQuery。
var table = document.getElememtsByTagName("table")[0]; //if it is the first or only table, you could change 0 to any other number if the table always is at the same position
,或者你可以给你的表中的ID:
var table = document.getElementById("my-table");
获得HTML就叫
var foo = table.innerHtml;
最简单的方法是使用jQuery来选择表格并返回HTML。例如$('table').html()
将返回一个<table>
标记的字符串。
我怎样才能得到正是我想要的表(有很多表上这一页)? 你能提供代码的例子吗? – user1062554
用我的示例中的'table'替换为特定于表的'#id'。 – abraham
正如您所看到的,此表中没有ID,并且我无法为该表提供ID(如果我可以这样做,为什么需要Chrome扩展?)。 – user1062554
谢谢! getElementsByTagName(not getElememtsByTagName) – user1062554