简体   繁体   English

jQuery不触发内把手模板

[英]Jquery not firing inside handlebars template

I have Javascript directory search that uses jquery and jquery UI code that works on it's own page but as soon as I use the handlebars templates, the on submit function isn't registering or firing anything: 我有使用jquery和jquery UI代码在其自己的页面上工作的Javascript目录搜索,但是一旦我使用车把模板,on Submit函数就不会注册或触发任何事情:

$(".navbar-form").submit(function () {
        var a = $("#searchFullName").val();
        var currentTab = '';
        $('li.active').each(function(index) {
           currentTab = $(this).find('a').html();       
        });
        getFirstAndLastName(a);
        if(currentTab == 'Student')
            callStudentWebService();
        if(currentTab == 'Faculty/Staff')
            callStaffWebService();
        $('#searchFullName').blur();
        return false;
});

HTML and JS pasted here: http://jsfiddle.net/5Cr9s/ HTML和JS粘贴在这里: http : //jsfiddle.net/5Cr9s/

Is it possible to reload the Javascript file(s) when a template changes in handlebars? 当模板在车把中更改时,是否可以重新加载Javascript文件? I'm really stuck here. 我真的被困在这里。

Thanks so much charlietfl! 非常感谢charlietfl!

$( "body" ).delegate( "form", "submit", function() { 
...

This worked like a charm! 这就像一个魅力!

This worked in my case where I use select with event delegation 这在我将select与事件委托结合使用的情况下有效

$("body").delegate('select[name="carType"]', 'change',function () {
        var selectedOption = $("option:selected", this);
        var val = this.value;
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM