gpt4 book ai didi

jquery - 如何在 Meteor 1.0 中使用 jQuery

转载 作者:行者123 更新时间:2023-12-03 22:29:08 25 4
gpt4 key购买 nike

我正在尝试在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();
}
});

关于jquery - 如何在 Meteor 1.0 中使用 jQuery,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27116880/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com