点击车把模板中的字体真棒图标

问题描述 投票:1回答:1

我有一些麻烦,点击它是动态创建一个字体真棒图标时触发酥料饼。

index.ejs

<!-- Template for Snazzy Window -->
<script id="marker-content-template" type="text/x-handlebars-template">
    <div class="custom-img" style="background-image: url({{{bgImg}}})"></div>
    <section class="custom-content">
        <h1 class="custom-header">
            {{title}} <i class="fa fa-question-circle" data-placement="right" data-toggle="popover" data-container="body" data-content="And here's some amazing content. It's very engaging. Right?"></i>
            <small>{{governance}}</small>
        </h1>
        <div class="custom-body">{{{body}}}</div>
    </section>
</script>

<script type="text/javascript>
  $(function() {
    var template = Handlebars.compile($('#marker-content-template').html());
  });
</script>

我已经试过各种方法,包括

$(document).on('click', '.fa', function(){
  $('[data-toggle="popover"]').popover('toggle');
});

这是不行的,现在我想它有事情做与车把模板?

我该如何处理这个?

javascript jquery handlebars.js
1个回答
1
投票

当你运行

$(document).on('click', '.fa', function(){
  $('[data-toggle="popover"]').popover('toggle');
});

,车把创建的元件,但没有其添加到DOM。

因此,在你的代码

// 1. Create the element from template with handlebar
var template = Handlebars.compile($('#marker-content-template').html()); 
// 2. Add the element to the DOM
document.getElementById('#yourTargetContainerId').innerHTML = template;
// 3. add the eventlistener to the elements
$(document).on('click', '.fa', function(){
  $('[data-toggle="popover"]').popover('toggle');
});
© www.soinside.com 2019 - 2024. All rights reserved.