在网页文本框中输入html代码怎么实现代码功能

如题所述

第1个回答  推荐于2017-12-16
很简单,其实就是相当于左边是个textarea输入域,右边是个代码解析,可用innerHtml.示例如下:
<html>
<head>
<script language="javascript">
function onsubm()
{
//document.getElementById("result").innerHTML=document.getElementById("text1").value;
result.innerHTML=document.getElementById("text1").value;
}

</script>
</head>
<body>
<div>
<font size="5" color="red">编辑您的代码:</font>
<span style="position:relative;left:500px"><font size="5" color="red">查看结果:</font></span></div>
<div style="width:600px;height:400px;border:1px solid blue;float:left;">
<form onsubmit="onsubm()" action="#">
<textarea rows="20" cols="80" id="text1">
</textarea>
<input type="submit" value="提交代码"/>
</form>
</div>
<div id="result" style="width:300px;height:400px;border:1px solid blue;float:left;">
</div>
</body>
</html>本回答被提问者采纳
相似回答