[英]Send html as value to textarea
我有一个文本框,在其中放置信息以使用以下html和脚本基于该搜索获取新信息:
HTML:
<input name="line" placeholder="Line" onkeydown="if (event.keyCode == 13) { calculate(); return false; }" style="width:40px;" type="textbox">
<input value="Reset" type="reset">
<input id="call" placeholder="Entrepreneur" style="width:95px;" type="textbox">
<input id="number" placeholder="Phonenumber" style="width:110px;" type="textbox">
脚本:
function calculate() {
var line = document.buss.line.value;
var ent;
var num;
switch(line) {
case "12":
case "27":
case "30":
<-- a lot of cases -->
ent = "Entrepreneur";
num = "Phonenumber";
break;
case "42":
case "63":
case "69":
<-- a lot of cases -->
ent = "Entrepreneur";
num = "Number";
break;
default:
}
document.buss.call.value = ent;
document.buss.number.value = num;
}
所有这些工作都完美无缺,但是现在我需要在文本区域中输入一些新信息,但是我无法以我想要的方式打印它。 我要提供的信息是
但是现在它以文本而不是html的形式打印出来,有没有办法改变它? 还有没有一种方法可以直接将其打印到页面上,而不需要使用大量的文本框和文本区域?
HTML:
<input name="line" placeholder="Line" onkeydown="if (event.keyCode == 13) { calculate(); return false; }" style="width:40px;" type="textbox">
<input value="Reset" type="reset">
<input id="call" placeholder="Entrepreneur" style="width:114px;" type="textbox">
<input id="number" placeholder="Number" style="width:90px;" type="textbox">
<textarea id="stop" placeholder="Stop" style="width:300px; height:650px"></textarea>
脚本:
function calculate() {
var line = document.buss.line.value;
var ent;
var num;
var stop;
switch(line) {
case "1":
ent = "Entrepreneur";
num = "Number";
stop = "<b>stop1</b><br>stop2<br>stop3<br><b>stop4</b>";
break;
case "2":
ent = "Entrepreneur";
num = "Number";
stop = "<b>stop1</b><br>stop2<br>stop3<br><b>stop4</b>";
break;
default:
}
document.buss.call.value = ent;
document.buss.number.value = num;
document.buss.stop.value = stop;
}
您无法在Textarea对象内呈现html。 如果您不需要文本是可编辑的,则可以使用div或span标签替换输入和textarea,并替换其内容。
例:
如果您替换此:
<textarea id="stop" placeholder="Stop" style="width:300px; height:650px"></textarea>
有了这个:
<div id="stop" style="width:300px; height:650px">Stop</div>
并替换为:
document.buss.stop.value = stop;
有了这个:
document.getElementById('stop').innerHTML = stop;
html被渲染。
要使“重置按钮”起作用,您将需要添加重置功能。 这应该可以解决问题:
<input onclick="resetHtml()" value="Reset" type="reset">
function resetHtml() {
document.getElementById('stop').innerHTML = "Stop";
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.