如何在innerhtml函数中包含花括号

时间:2014-04-29 16:31:45

标签: javascript ember.js handlebars.js

您好我正在尝试使用以下功能:

<script>
$(function(){
 document.getElementById("alert").innerHTML="<button {{action 'alert'}}>i</button>";
 });
</script>

然而,html呈现为:

<button 'alert'}}="" {{action="">i</button>

我已经搜索过,无法找到解决方案,感谢任何帮助。

1 个答案:

答案 0 :(得分:-1)

您可以使用斜杠表示法转义字符

\{ 

或者您可以使用他们的unicode值来解析特殊字符。这是一张好图表:

http://www.hardweb.com.au/XHTMLnumericalcharacterreferencecode1to999javascript.html