【发布时间】:2020-07-22 19:27:01
【问题描述】:
我正在创建一个博客网站。我正在使用 textarea 获取输入并将其存储在 MongoDB 中。用于显示我使用的数据:white-space: pre-wrap;。
如果我将输入输入为:
hello
world
输出是:
hello
world
我希望输出为:
hello
world
代码: 接受输入:
<form action="/post/compose" method="post">
<div class="form-group">
<label for="postTitle">Title</label>
<input type="text" class="form-control" name="postTitle" >
<label for="postBody">Body</label>
<textarea class="form-control" name="postBody" rows="10" col="10"></textarea>
</div>
<button class="btn btn-success" type="submit">Publish</button>
</form>
将输入存储在数据库中:
const post=new Post({
Title:req.body.postTitle,
Content:req.body.postBody,
});
post.save();
显示输入
<div id="fullpost">
<h2 class="text-dark"><%= post.Title %></h2>
<p class="text-dark" id="Postcontent"><%- post.Content %></p>
</div>
css:
#Postcontent{
white-space: pre-wrap;
}
现在我添加了 white-space 属性,如果输入中有 \n ,则在输出中包含单个空格。但我想要两个空格。 是否可以在没有 Javascript 中的正则表达式的情况下做到这一点?请帮忙。提前致谢。
【问题讨论】:
-
那么我怎样才能将 \n 添加到用户输入中?
-
一点上下文会有所帮助。你应该发布你的代码
-
@FlorentArlandis 嘿!感谢您的回复。我添加了一些代码。
-
您希望在每个条目后有一个新的空白行,还是希望文本在显示的每行文本之间显示 100% 的行高?
标签: javascript html css node.js express