我想在页面上创建实时 HTML/CSS 预览。
但是代码不会使用 textareas 给出。代码将在页面 ( div
) 中修复。
我希望用户能够更改代码,这将反映在实时预览框中。我创建了一个页面,您可以在其中更改部分脚本文本(对于业余爱好者)。你可以在这里预览:http: //apolosiskos.co.uk/HTML-CSS-EDITOR/index3.html
01)如果我textarea
用div
.
02)即使我使用 textareas,实时预览也不起作用,因为在我的 HTML 脚本中我使用了code
和xmp
标签。
--> 适用于 textarea 但不适用于 div 的片段:
var wpcomment = document.getElementById('WPComment');
wpcomment.blur = wpcomment.onkeypress = function(){
document.getElementById('prevCom').innerHTML = this.value;
}
#prevCom
{
background:#124;
color:#fff;
min-width:20px;
min-height:50px;
font-size:25pt;
}
<textarea name="WPcomment" id="WPComment" placeholder="Add comments:">aaaaa</textarea>
<div id="prevCom"></div>