本文介绍了如何使用JavaScript在iFrame中删除HTML元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个iFrame和一个包含内容的div。我想通过JavaScript删除div,这是可能的,我怎么能做到这一点?



我不想只显示它(例如 display:none 通过CSS),但将其从网站的HTML中移除。我对JavaScript有基本的了解,但是没有任何使用iFrame的经验。
$ b $

  $(#iFrameId)。contents()。find(#yourDiv)。empty(); 

最好使用 remove()


$ b

示例: $(#iFrameId)。contents()。find(#yourDiv)。remove();

解释

空( )将删除所有选择内容。



remove()将会移除选择及其内容以及与之相关的所有事件处理程序。

仅供参考:
1)
2)


I have an iFrame and a div with content in it. I want to delete the div via JavaScript, is that possible and how could I do that?

I don't want to just not display it (eg. display: none via CSS) but remove it from the HTML of the site. I have basic knowledge of JavaScript but don't have any experience working with an iFrame.

解决方案

You can use

$("#iFrameId").contents().find("#yourDiv").empty();

It is better to use remove()

example: $("#iFrameId").contents().find("#yourDiv").remove();

Explaination

empty() will remove all the contents of the selection.

remove() will remove the selection and its contents and all the event handlers associated with it.

For reference:1) http://api.jquery.com/remove/2) http://api.jquery.com/empty/

这篇关于如何使用JavaScript在iFrame中删除HTML元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 23:47