NodeJs项目如何让用户在表单中输入未初始化



我在NodeJs项目中使用了一个表单:

app.use(bodyParser.urlencoded({extended: true}));

如果用户在表单中输入<h1>hello</h1>,它将显示为"你好",格式为h1,而不是<h1>hello</h1>

<form action="/blogs" method="POST">
<div class="form-group">
<input class="form-control" type="text" name="name" placeholder="name">
</div>
<div class="form-group">
<input class="form-control" type="text" name="image" placeholder="image url">
</div>
<div class="form-group">
<input class="form-control" type="text" name="description" placeholder="description">
</div>
<div class="form-group">
<button class="btn btn-lg btn-primary btn-block">
Submit
</button>
</div>  
</form>

我找到了解决问题的方法。在Node.js中,如果您想将信息显示为HTML,请在index.ejs文件中你需要做一个<%-blog.description%>,其中短划线是关键。在我之前<%=blog.description%>。

最新更新