我正在尝试将 html 字符串作为 res.render()
发送参数并在客户端将其呈现为 html。如何让浏览器将其识别为 html 而不是字符串?这能做到吗?
主页.hbs
<div id="results">
{{#each results}}
<p>{{this}}</p>
{{/each}}
</div>
服务器.js
app.get('\', (req,res) => {
let results = ['<mark>This</mark> is highlighted.']
res.render('home', {results: results});
})
在我的网页中,我希望它看起来像一个突出显示“This”一词的段落(因为 <mark>
),但它显示为 <mark>This</mark> is highlighted.
其中 This
不突出显示,标记标记为纯文本。
最佳答案
使用“triple-stash”取消html转义功能。
https://handlebars-lang.github.io/docs/guide/#html-escaping
关于javascript - 如何发送 res.render 字符串参数并将其呈现为 HTML?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57384421/