【发布时间】:2023-03-12 18:06:01
【问题描述】:
这是我尝试构建实时 html 编辑器的代码。在 javascript 中,我从 id=pure 的 textarea 获取文本,然后在 document.body.onkeyup 函数中,我将值传递给 id= 的 textarea编译。它根本不起作用。我想知道问题是关于 open-writeln-close 还是其他语法?
function compile() {
var h = document.getElementById("pure");
var compiled = document.getElementById("compiled").contentWindow.document;
document.body.onkeyup = function(){
compiled.open();
compiled.writeln(h.value);
compiled.close();
};
}
compile();
<div class="form-group">
<label for="html">Write your HTML here:</label>
<textarea class="form-control" rows="3" id="pure"></textarea><br>
<textarea class="form-control" rows="2" id="compiled"></textarea>
</div>
【问题讨论】:
-
我很确定您的意思是
<iframe>作为编译输出。<textarea>没有contentWindow
标签: javascript html editor real-time