当我按回车键将我的行放入 <p>
时,我更确切地想要例如:
<p>HELLO</p>
<p>Another line</p>
<p>Line 3</p>
在数据库中这样上传
这是我要执行此操作的代码
<div class="form-group">
<label for="phone-pin">Text</label>
<textarea type="text" class="form-control" id="text-area-first" name="text-area-first" required placeholder="text"></textarea>
</div>
最佳答案
这是一个解决方案。
function store() {
var txt = document.getElementById("text-area-first").value;
var txttostore = '<p>' + txt.replace(/\n/g, "</p>\n<p>") + '</p>';
console.log(txttostore);
}
<div class="form-group">
<label for="phone-pin">Text</label>
<br>
<textarea type="text" class="form-control" id="text-area-first" name="text-area-first" required placeholder="text"></textarea>
<br>
<button id="store" onclick="store()">Store</button>
</div>
关于html - 如何将文本区域中的文本放入段落中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39293298/