【发布时间】:2015-11-18 21:50:32
【问题描述】:
如何让模板中的换行符显示在文本区域中?
我试图在, 之后的每个模板中添加一个换行符,并且我认为由于使用.value 而不能使用</ br>。
我尝试了JavaScript: How to add line breaks to an HTML textarea? 和javascript | save textarea value with line breaks 以及使用style="white-space:pre-wrap" 的建议。
var template_Birthday = "Hey <NAME>, This is the Birthday Template.";
var template_NewJob = "Hey <NAME>, This is the New Job Template.";
var content = function() {
var e = document.getElementById("template");
var strUser = e.options[e.selectedIndex].value;
if (strUser === "template_NewJob") {
messageBodyTextarea.value = template_NewJob;
} else if (strUser === "template_Birthday") {
messageBodyTextarea.value = template_Birthday;
}
};
<textarea class="form-control" rows="7" name="message" id="messageBodyTextarea"></textarea>
【问题讨论】:
-
请提供小提琴?
-
\n是换行符的转义码
标签: javascript jquery html