我有,例如:
<iframe width="700px" src="/top_list.html"></iframe>
如何从该框架中删除除 table .. 之外的所有内容,或者用户如何仅看到该页面中的表格内容?
如果没有唯一标识符并且您无法更改 top_list 页面,您可以使用 jquery .hide() 隐藏您不想显示的所有内容。
您需要一些 jquery 工具:
.main
我的示例对查询非常明确。没有链接,所以你可以看到发生了什么。我希望它有所帮助。
$(window).on('load', function() // wait for load event, so the iframe is fully loaded in
{
var $iframe = $('iframe'); // assuming only one? You need to target the right iframe, perahps with iframe[src="/top_list.html"] if that's your only option
var $contents = $iframe.contents();
var $main = $contents.find('.main');
var $tbl = $main.next(); // now we have the table
$contents.find('*').hide(); // hide everything
$tbl.show(); // show table and...
var $parent = $tbl.parent(); // get/show all parents of the tbl
while($parent.length)
{
$parent.show(); // show parent
$parent = $parent.parent(); // move up the hierarchy
}
});