how to escape <> in javascript underscore template?

元气小坏坏 提交于 2019-11-30 04:46:19

问题


when using underscore template i want to interpolate a value in anchor's href attribute like

a(href= "<%= id %>", class='products') //underscore template in jade

but the out put is

<a href="&lt;% id %&gt;" class="products"> 

so how to escape the < and > sign , and interpolate the value correctly?


回答1:


Use != instead of = to unescape.

In your case:

a.products(href!="<%= id %>")


来源:https://stackoverflow.com/questions/12362290/how-to-escape-in-javascript-underscore-template

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!