逃避HTML值是什么意思?

Pee*_*per 6 html javascript handlebars.js

Handlebars HTML-escapes返回的值{{expression}}.如果您不希望Handlebars转义值,请使用"triple-stash",{{{

HTML-escape值是什么意思?

wsc*_*rge 5

以下字符在 HTML 中保留,必须替换为相应的 HTML 实体:~ (在线 HTML 格式化程序)

  • "被替换为"
  • &被替换为&
  • <被替换为&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));
Run Code Online (Sandbox Code Playgroud)
<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>
Run Code Online (Sandbox Code Playgroud)

然后,handlebarsjs.com关于此事的内容也值得一读。