Jquery Iframe删除除<table> </table>之外的所有元素

时间:2013-01-31 18:01:39

标签: jquery replace

我有,例如:

    <iframe width="700px" src="/top_list.html"></iframe>

如何删除此框架中除表格以外的所有内容..或者用户如何仅查看该页面中的表格内容?

2 个答案:

答案 0 :(得分:0)

如果没有唯一标识符且您无法更改top_list页面,则可以使用jquery .hide()隐藏您不想显示的所有内容。

答案 1 :(得分:0)

您需要一些jquery工具:

我的例子对查询非常明确。没有链接,所以你可以看到发生了什么。我希望它有所帮助。

$(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
  }
});