是否有可能在handlebars.js模板中使用JavaScript [英] Is it possible to use JavaScript inside handlebars.js template
本文介绍了是否有可能在handlebars.js模板中使用JavaScript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在脚本模板中添加JavaScript脚本。
我想为我的网站创建一个动态的PayPal按钮。
< script type =text / x-mustache-templateid =product-item-thumbnail-template>
< h2> {{title}}< / h2>
< p> {{message}}< / p>
< p>< a class =btnhref =#>查看详情& raquo;< / a>< / p>
< p>< script src =resources/js-frameworks/paypal-button.min.js?merchant=myemail@GMAIL.COM
data-button =buynow
data-name =我的产品
data-amount =1.00>< / script>< / p>
< / script>
但由于标签的原因,这会产生错误。它关闭了模板脚本而不是PayPal脚本
谢谢
解决方案
尝试分解/ script部分:
< script ...> ;< {{}!} /脚本>
该技术类似于旧版hack,比如
<脚本>文件撰写( <脚本> ...< \ /脚本> 中);< /脚本>
The description says it all. How to put a JavaScript script inside handlebars template.
I want to make a dynamic Paypal button for my website.
<script type="text/x-mustache-template" id="product-item-thumbnail-template"> <h2>{{title}}</h2> <p>{{message}}</p> <p><a class="btn" href="#">View details »</a></p> <p><script src="resources/js-frameworks/paypal-button.min.js?merchant=myemail@GMAIL.COM" data-button="buynow" data-name="My product" data-amount="1.00"></script></p> </script>
But this produces an error because of the tag. it closes the template script and not the paypal script
Thanks
解决方案
Try breaking up the "/script" part:
<script ...><{{!}}/script>
That technique is similar to older hacks like
<script>document.write("<script>...<\/script>");</script>
这篇关于是否有可能在handlebars.js模板中使用JavaScript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文