How to render HTML as rendered HTML in jQuery.tmpl()?

房东的猫 提交于 2019-12-07 03:07:51

问题


I can't assign HTML properly using jQuery.tmpl(). If i pass value of something as html tag it is rendered as as it is instead of HTML tags rendered on page

<div id="window">
    <script id="lines" type="text/x-jquery-tmpl">
        <div id="${id}" class="line ${type}"><span>${name}</span>: ${body}</div>
    </script>
</div>



var line = {
            name: 'John',
            body: '<strong>hello</strong>
        };
        $('#lines').tmpl(line).appendTo('#window');

回答1:


You can wrap the template variable with {{html body}} to override the default encoding behavior.



来源:https://stackoverflow.com/questions/6248962/how-to-render-html-as-rendered-html-in-jquery-tmpl

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