如何使用 JavaScript 删除 iFrame 中的 HTML 元素 [英] How to delete HTML Elements in an iFrame using JavaScript
问题描述
我有一个 iFrame 和一个包含内容的 div.我想通过 JavaScript 删除 div,这可能吗,我该怎么做?
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?
我不想只是不显示它(例如,display: none
通过 CSS)而是从网站的 HTML 中删除它.我有 JavaScript 的基本知识,但没有任何使用 iFrame 的经验.
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.
推荐答案
您可以使用
$("#iFrameId").contents().find("#yourDiv").empty();
最好使用remove()
示例:$("#iFrameId").contents().find("#yourDiv").remove();
说明
empty()
将删除选择的所有内容.
empty()
will remove all the contents of the selection.
remove()
将删除选择及其内容以及与其关联的所有事件处理程序.
remove()
will remove the selection and its contents and all the event handlers associated with it.
供参考:1) http://api.jquery.com/remove/2) http://api.jquery.com/empty/
这篇关于如何使用 JavaScript 删除 iFrame 中的 HTML 元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!