Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/434.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在文本区域而不是html代码中显示html输出_Javascript_Textarea - Fatal编程技术网

Javascript 在文本区域而不是html代码中显示html输出

Javascript 在文本区域而不是html代码中显示html输出,javascript,textarea,Javascript,Textarea,如果我有一个包含一些HTML代码的文本区域,我如何编写JavaScript函数来显示HTML输出,而不是HTML代码本身,例如: <textarea id="mytextarea"> <table border=1><tr><td>cellone</td>td>celltwo</td></tr></table </textarea> <input type=button onclic

如果我有一个包含一些HTML代码的文本区域,我如何编写JavaScript函数来显示HTML输出,而不是HTML代码本身,例如:

<textarea id="mytextarea">
<table border=1><tr><td>cellone</td>td>celltwo</td></tr></table
</textarea>
<input type=button onclick="HTMLoutput();"/>

<script>
HTMLoutput()
{
//Code to show html output instead of html code in textarea
}
</script>


CellNetd>celltwo听起来像是在问如何获取一些HTML并在文档中显示其呈现结果

这正是
innerHTML
属性所做的。

只需选择一个DOM元素来显示结果,并将其
innerHTML
设置为要显示的HTML。

因此,要将HTML代码转换为格式化的HTML,您需要执行以下操作:

$('resultDiv').append($('<div/>').html($('.txtArea').val()+"<br>");
$('resultDiv').append($('').html($('.txtArea').val()+“
”);

下面是将contentEditable设置为true时使用div的示例。

我想构建一个编辑器,并在textarea内部显示渲染结果作为preview@user2888402:
只能显示纯文本。您可以使用CSS在文本框顶部显示预览。谢谢@Slaks您能给我一个示例吗这是使用CSS吗?