<脚本>Underscore.js 模板中的标签?脚本>
我在运行 Underscore 模板内的嵌套 JavaScript 时遇到问题。
<script type="text/template" id="myTemplate">
<h3><%= heading %></h3>
<div class="container"></div>
//THIS DOES NOT WORK --->
<script type="text/javascript" charset="utf-8">
$(".container").html("Test")
</script>
//END
</script>
这是否可能,或者我该如何解决这个问题? 谢谢。
I'm having trouble getting nested JavaScript inside Underscore templates to run.
<script type="text/template" id="myTemplate">
<h3><%= heading %></h3>
<div class="container"></div>
//THIS DOES NOT WORK --->
<script type="text/javascript" charset="utf-8">
$(".container").html("Test")
</script>
//END
</script>
Is this at all possible or how could I work around the issue?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我已经使用这种方法来模板化 html 页面。
I have used this method for templating an html page.
我必须这样做,因为我必须生成未知数量的函数。
I had to do so, because I had to generate an unknown number of functions.
Javascript 当然不属于模板。因此,它们不起作用才有意义。
如果需要执行与模板相关的脚本,请将它们放在一个函数中,并在渲染模板时调用它们。
Javascript certainly doesn't belong into a template. So it only makes sense that they do not work.
If you need to execute scripts related to the template, put them in a function and call them when you render the template.