gpt4 book ai didi

javascript - 转义 HTML 值是什么意思?

转载 作者:搜寻专家 更新时间:2023-10-31 22:24:41 24 4
gpt4 key购买 nike

Handlebars HTML-escapes values returned by a {{expression}}. If you don't want Handlebars to escape a value, use the "triple-stash", {{{

HTML 转义值是什么意思?

最佳答案

The following characters are reserved in HTML and must be replaced with their corresponding HTML entities: ~(Online HTML Formatter)

  • "替换为 "
  • &替换为 &
  • <替换为 &lt;
  • >替换为 &gt;

例子说一千多个字:

var source   = $("#template").html(); 
var template = Handlebars.compile(source);

var data = {
escaped : '{{}}',
notescaped: '{{{}}}',
html : "<a href='https://google.com/'>Google <strong>Search</strong></a>",
}

$('body').append(template(data));
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/handlebars.js/4.0.11/handlebars.min.js"></script>
<script id="template" type="text/x-handlebars-template">

<h4>Escaped HTML double curly brackets: <code>{{escaped}}</code></h4>
{{html}}
<p>It's just non interactive string</p>

<hr>

<h4>Not escaped HTML tripple curly brackets: <code>{{notescaped}}</code></h4>
{{{html}}}

<p>It basically ends up as parsed HTML</p>




</script>

然后,handlebarsjs.com关于此事也是一本好书。

关于javascript - 转义 HTML 值是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48531908/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com