我试图在Meteor应用程序中包含Google Plus One按钮以进行协作草图绘制,我注意到script模板内的标签未执行.
<template name="gplus">
<!-- Place this tag where you want the +1 button to render. -->
<div class="g-plusone" data-href="{{url}}"></div>
<!-- Place this tag after the last +1 button tag. -->
<script type="text/javascript">
console.log("Google Plus button");
(function() {
var po = document.createElement('script');
po.type = 'text/javascript';
po.async = true;
po.src = 'https://apis.google.com/js/plusone.js';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(po, s);
})();
</script>
</template>
Run Code Online (Sandbox Code Playgroud)
我通过将脚本移动到单独的JavaScript文件来获得工作按钮,但我仍然想知道为什么内联脚本不起作用.
我在控制台上看到了脚本标记,但脚本本身并没有运行.Meteor如何做到这一点?
Meteor 只是将 gplus 模板的内容插入到 DOM 中,所以当然不会发生任何事情,因为将元素添加到 DOM 时没有执行任何脚本。
要解决此问题,您可以创建一个 .js 文件并将其放入客户端文件夹中,Meteor 将自动包含并为您执行该文件(以及在生产中缩小)。
| 归档时间: |
|
| 查看次数: |
2050 次 |
| 最近记录: |