【问题标题】:textarea html tags get converted to plain text [closed]textarea html标签被转换为纯文本[关闭]
【发布时间】:2016-03-22 18:10:14
【问题描述】:

我正在使用 CKEditor 向网站发帖。但是,我输入了一些创建 HTML 标记的内容,但它们以纯文本形式返回:

Plain-text image

我将它们输入为: HTML post

我正在为我的视图引擎使用 EJS(如果重要的话),显示帖子的代码是:

<ul class="main-posts">
          <% for(var i=0; i < posts.length; i++) { %>
            <div class="postbg">
             <li class="li-post"><strong><%= posts[i].pTitle %></strong></li>
             <li class="li-author"><strong>Author:</strong> <%= posts[i].author %></li>
             <li class="li-content"><%= posts[i].content %></li>
           </div>
             <br />
          <% }; %>
        </ul>

还有我的帖子功能:

exports.posts = function(req, res) {
var time = moment().format("hh:mm A MM/DD/YYYY");
new Post({
author: req.body.author,
content: req.body.content,
pTitle: req.body.pTitle,
date: time
}).save(function(err, post){
res.redirect('/');
});
};

【问题讨论】:

  • 将其总结为“&lt;%= posts[i].content %&gt; 输出 HTML 编码内容而不是原始 HTML”是否正确?

标签: javascript html node.js


【解决方案1】:

假设这是您所指的 EJS:http://ejs.co/,看起来您应该使用 &lt;%- %&gt; 来输出原始 HTML,如下所示:

<ul class="main-posts">
  <% for(var i=0; i < posts.length; i++) { %>
    <div class="postbg">
      <li class="li-post"><strong><%= posts[i].pTitle %></strong></li>
      <li class="li-author"><strong>Author:</strong> <%= posts[i].author %></li>
      <li class="li-content"><%- posts[i].content %></li>
    </div>
    <br />
  <% }; %>
</ul>

【讨论】:

  • 成功了!非常感谢!
猜你喜欢
  • 1970-01-01
  • 2014-04-21
  • 1970-01-01
  • 1970-01-01
  • 2014-02-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多