【问题标题】:href links are not detected in a index.ejs file [duplicate]在 index.ejs 文件中未检测到 href 链接[重复]
【发布时间】:2020-07-30 09:18:45
【问题描述】:

我有一个 nodeJS-HTML 应用程序。 html 文件接受一个表单并调用 nodeJS 函数,该函数处理一些数据并将一些信息发送回 hrml 文件。我正在使用视图来呈现需要发布的详细信息。

我的 app.js 有这行代码

res.render('index.ejs', { collection: data})

数据为 JSON 格式

"Name": "Chegg",
"Description" : "In February 2018, the diet and exercise service <a href=\"https://abc/FAQ.html\" target=\"_blank\" rel=\"noopener\">ABC suffered a loss</a>.

我的 index.ejs 看起来像这样

<% for(var i=0; i<collection.length; i++) {%>
                    <div>
                     <p align="left"><%= collection[i].Domain %> </p> <br>
                     <p align="left"><%= collection[i].Description %> </p> <br>
                     <!-- <td><%= collection[i] %></td> -->
                    </div>
                  <% } 
%>

这里的所有内容都正确填充,除了描述。链接不是超链接 - 而是纯文本。

有没有办法显示超链接?

【问题讨论】:

  • 使用-而不是=来输出未转义的值。 &lt;%- collection[i].Description %&gt;
  • 太棒了。非常感谢
  • @dimitristseggenes 你拯救了我的一天。您的评论应该是可接受的答案

标签: html node.js ejs


【解决方案1】:

正如@dimitristseggenes 所述,超链接适用于-,但不适用于=

改变

<%= collection[i].Description %>

<%- collection[i].Description %>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-03-26
    • 1970-01-01
    • 2023-03-27
    • 2020-02-23
    • 2015-02-02
    • 2016-03-04
    • 2013-03-27
    相关资源
    最近更新 更多