[英]Send html as value to textarea
I have a textbox where I put info to get new info based on that search using the folling html & script: 我有一个文本框,在其中放置信息以使用以下html和脚本基于该搜索获取新信息:
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">
SCRIPT: 脚本:
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;
}
All this works perfect but now I needed to put in some new information in a textarea but I can not get it to print the way I want. 所有这些工作都完美无缺,但是现在我需要在文本区域中输入一些新信息,但是我无法以我想要的方式打印它。 What I want is for the information to incude and 我要提供的信息是
but right now it prints this as text instead of html, is there a way to change this? 但是现在它以文本而不是html的形式打印出来,有没有办法改变它? also is there a way to print it directly to the page instead of having a lot of textboxes and 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:114px;" type="textbox">
<input id="number" placeholder="Number" style="width:90px;" type="textbox">
<textarea id="stop" placeholder="Stop" style="width:300px; height:650px"></textarea>
SCRIPT: 脚本:
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;
}
You can't render html inside a Textarea object. 您无法在Textarea对象内呈现html。 If you dont need the text to be editable, you can replace the inputs and textarea with div ou span tags, and replace it's content. 如果您不需要文本是可编辑的,则可以使用div或span标签替换输入和textarea,并替换其内容。
Example: 例:
If you replace this: 如果您替换此:
<textarea id="stop" placeholder="Stop" style="width:300px; height:650px"></textarea>
With this: 有了这个:
<div id="stop" style="width:300px; height:650px">Stop</div>
And replace this: 并替换为:
document.buss.stop.value = stop;
With this: 有了这个:
document.getElementById('stop').innerHTML = stop;
The html is rendered. html被渲染。
To make the Reset Button work, you will need to add a reset function. 要使“重置按钮”起作用,您将需要添加重置功能。 This should do the trick: 这应该可以解决问题:
<input onclick="resetHtml()" value="Reset" type="reset">
function resetHtml() {
document.getElementById('stop').innerHTML = "Stop";
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.