如何在Meteor 1.0中使用jQuery

我试图在meteor.js应用程序中使用这样的 jquery.

JS:

if (Meteor.isClient) {      
    Meteor.startup(function() {
            $( "button" ).click(function() {
              $( "p" ).toggle();
            });
          });
...

或者没有meteor.startup函数.两者都不起作用.

HTML:

<button>Click</button>
<p>Can you see me?</p>

我没有错误,单击按钮时没有任何反应.

解决方法

您不应该像这样使用jQuery进行简单的事件处理,而是使用Meteor模板事件映射:

HTML:

<template name="myTemplate">
  <button type="button">Click me !</button>
  <p>Can you see me ?</p>
</template>

JS:

Template.myTemplate.events({
  "click button":function(event,template){
    template.$("p").toggle();
  }
});

相关文章

页面搜索关键词突出 // 页面搜索关键词突出 $(function () {...
jQuery实时显示日期、时间 html: &lt;span id=&quot...
jQuery 添加水印 &lt;script src=&quot;../../../.....
中文:Sys.WebForms.PageRequestManagerParserErrorExceptio...
1. 用Response.Write方法 代码如下: Response.Write(&q...
Jquery实现按钮点击遮罩加载,处理完后恢复 思路: 1.点击按...