在不使用JQuery的情况下更改IFrame中的文本

Change Text in IFrame without JQuery

本文关键字:IFrame 文本 情况下 JQuery      更新时间:2024-02-07

编织:http://kodeweave.sourceforge.net/editor/#f6d9a54288f17fb68a8b234ec364dc41

我喜欢JQuery,但为了好玩,我想学习如何用纯/香草JS编写以下内容。

$("iframe").contents().find("<style>").html(cssEditor.value)) 

这样的东西应该可以工作:

document
    .getElementsByTagName('iframe')[0]
        .contentDocument
            .getElementsByTagName('style')[0]
                .innerHTML = cssEditor.value;

使用<iframe> DOM对象的contentDocument属性来获取内部文档。

然后可以调用它上的普通方法,如querySelector