我有一个文本区域,我不想在其中添加组成完整网页的 HTML 代码,当我键入时,此内容将在 iframe 中呈现
例如,在文本区域中我将编写以下代码:
<!DOCTYPE html>
<html>
<head>
<title>Live generate</title>
<style></style>
</head>
<body>
</body>
</html>
我的问题是我不知道如何访问 iFrame 来更改其完整内容,使其与上面的内容匹配
最佳答案
您应该能够通过 document.getElementById 的 id 或通过 jquery 获取 iframe,然后获取其文档,打开它并写入内容。
喜欢:
var iframe = $("iframe"); // or by Id $("#myIframeId")
var doc = iframe.document;
doc.open();
doc.write($("#myTextArea").text());
doc.close();
关于javascript - 更改 iFrame 的全部内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10190118/