是否可以在Meteor事件映射中使用嵌套选择器? [英] Is it possible to use nested selectors in Meteor event maps?

查看:111
本文介绍了是否可以在Meteor事件映射中使用嵌套选择器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在这里,我想从 .header 元素中选择 .accept 元素。这可能吗? 文档无法确定,我已尝试了一些变体无法使用,是否有骗子我不是意识到?

Here, I would like to select the .accept element from within the .header element. Is this possible? The documentation is inconclusive and I have tried some variations to no avail, is there a trick I'm not aware of?

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

在jQuery中我可以使用这个: $('。header .accept')

In jQuery I might use this: $('.header .accept')

推荐答案

您分享的内容会假设您在其他地方没有冲突。尝试使用下面的代码。

What you shared will work assuming you don't have a conflict elsewhere. Try using the code below. The event fires only if you click the second div, as you want.

模板:

<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');
        }
    });
}

这篇关于是否可以在Meteor事件映射中使用嵌套选择器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆