在textarea中添加行 [英] add line in textarea
本文介绍了在textarea中添加行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个textarea。单击按钮将值插入textarea
I have a textarea. the value is inserted in the textarea on the click of a button
function addText(elId,text) {
if(document.getElementById("NewJudge").value != "")
{
var text_area_id = document.getElementById("hc_judge");
var judge_name =(document.getElementById("NewJudge").value + " , ") ;
var txt = document.createTextNode(judge_name);
text_area_id.appendChild(txt);
document.getElementById("NewJudge").value ="";
}
}
我使用','来分隔textarea中的值。但是新的价值应该是一个新的界限。
我在网上搜索并发现'& #13; &安培; #10;'用于在textarea中添加新行。但是当我使用这段代码时
I used ',' to seperate values in the textarea. but the new values should be in a new line.
I searched the net and found that '& #13; & #10;' is used to add new line in textarea. But when I use this code
<pre lang="Javascript">
function addText(elId,text) {
if(document.getElementById("NewJudge").value != "")
{
var text_area_id = document.getElementById("hc_judge");
var judge_name =(document.getElementById("NewJudge").value + " & #13;& #10; ") ;
var txt = document.createTextNode(judge_name);
text_area_id.appendChild(txt);
document.getElementById("NewJudge").value ="";
}
}
</pre>
。
它保持文本不变。
i故意在&之间放置空格#因为它在这里创建了一个新行:D
但是当在代码中使用时它不起作用。请帮忙。在此先感谢:)
.
it keeps the text as it is.
i purposely put space between & # as it creates a new line here too :D
but when used in code it isnt working. Please help. Thanks in advance :)
推荐答案
你可以使用'\ n'作为换行符。
var judge_name =(document.getElementById(NewJudge)。value +'\ n');
you can use '\n ' as new line character.
var judge_name =(document.getElementById("NewJudge").value + '\n ') ;
这篇关于在textarea中添加行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文