2

在这里,我想.accept从元素中选择.header元素。这可能吗?文档没有定论,我尝试了一些变化无济于事,有什么我不知道的技巧吗?

'click .header .accept': function (event) { ... },

在 jQuery 中,我可能会使用这个:$('.header .accept')

4

1 回答 1

4

假设您在其他地方没有冲突,您共享的内容将起作用。尝试使用下面的代码。仅当您根据需要单击第二个 div 时才会触发该事件。

模板:

<body>
    {{> page}}
</body>

<template name="page">
    <div class="header">.header 
        <div class="accept">.header .accept</div>
    </div>
</template>

js:

if (Meteor.isClient) {
    Template.page.events({
        'click .header .accept': function(event) {
            console.log('accept clicked');
        }
    });
}
于 2013-01-21T23:13:16.173 回答