Javascript 如何在使用blaze呈现的新模板上实例化事件侦听器?

Javascript 如何在使用blaze呈现的新模板上实例化事件侦听器?,javascript,meteor,Javascript,Meteor,我有一个由Blaze呈现的模板,因为我创建了一个登录页,当用户单击“注册”按钮时,它会将其删除,然后转到Blaze呈现的另一个模板 HTML非常空白,只有一个div作为模板 <head> <title>Perform</title> </head> <body> <div id="template"> </div> </body> 有人知道我需要做什么才能激活“第二个”模板的事件吗?它只是不

我有一个由Blaze呈现的模板,因为我创建了一个登录页,当用户单击“注册”按钮时,它会将其删除,然后转到Blaze呈现的另一个模板

HTML非常空白,只有一个div作为模板

<head>
  <title>Perform</title>
</head>

<body>
<div id="template">
</div>

</body>
有人知道我需要做什么才能激活“第二个”模板的事件吗?它只是不起作用,现在有点令人沮丧


提前谢谢你的帮助。

好吧,我是个十足的白痴,最后自己解决了这个问题

第二个模板上的click事件实际上在测试和调试后工作,但是submit事件将不工作。这是两件完全不同的事情,我只是一个没有澄清这一点的白痴。为之前看到这一点并感到困惑的人道歉

而不是:

Template.second.events({
'submit #second_button': function(e, t) {
    // This console log is not firing.
    console.log("Register clicked");
    }
});
我把它改成:

Template.second.events({
'submit #second_button': function(e, t) {
    // This console log is now firing
    console.log("Register clicked");
    e.preventDefault()
    return false;

    }
});
var currentView;
var templateContainer;
$(document).ready(function() {

    templateContainer = document.getElementById('template');

    // This renders the first template. All events are currently working
    currentView = Blaze.render(Template.first, templateContainer);
});

Template.first.onDestroyed(function() {
    // This console.log is firing
    console.log("Destroyed first template");
});

Template.first.events({
    'click #first_button': function () {
    // Remove the first template with Blaze
    Blaze.remove(currentView);

    // Render the second template
    currentView = Blaze.render(Template.second, templateContainer);
    }
});


Template.second.onCreated(function() {
    // This console.log is firing when the 'second' template is created
    console.log("Hello! I've been created");
});
// The second template is actually a form I'd like to submit. Form omitted for brevity
Template.second.events({
    'submit #second_button': function(e, t) {
        // This console log is not firing.
        console.log("Register clicked");

    }
});
Template.second.events({
'submit #second_button': function(e, t) {
    // This console log is not firing.
    console.log("Register clicked");
    }
});
Template.second.events({
'submit #second_button': function(e, t) {
    // This console log is now firing
    console.log("Register clicked");
    e.preventDefault()
    return false;

    }
});