我想实现的内容就是,做了一个文本框,在里面输入html代码,点击submit,可以在后面显示结果。就和w3school里的测试工具差不多。这还function应该怎么写,还有一个就是在右边实现结果,那右边这个框应该是个什么属性的框?多谢大神
JS实现文本框内html代码怎么编写
答案:2 悬赏:30
解决时间 2021-02-05 03:10
- 提问者网友:℡她的他i☆
- 2021-02-04 05:32
最佳答案
- 二级知识专家网友:都不是誰的誰
- 2021-02-04 06:58
很简单,其实就是相当于左边是个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>
<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>
全部回答
- 1楼网友:废途浑身病态
- 2021-02-04 08:15
在js中,右边比如是个div,
var html_str = $("#text").val();
$('#div').html(html_str);
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯