首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >单击Handlebar模板中的Font Awesome图标

单击Handlebar模板中的Font Awesome图标
EN

Stack Overflow用户
提问于 2017-03-04 23:41:26
回答 1查看 650关注 0票数 1

当我点击一个动态创建的Font Awesome图标时,我遇到了一些触发弹出的问题。

index.ejs

代码语言:javascript
复制
<!-- 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>

我尝试过各种方法,包括

代码语言:javascript
复制
$(document).on('click', '.fa', function(){
  $('[data-toggle="popover"]').popover('toggle');
});

这不起作用,现在我在想这是不是和Handlebar模板有关?

我该如何处理这个问题呢?

EN

回答 1

Stack Overflow用户

发布于 2017-03-04 23:46:27

当您运行

代码语言:javascript
复制
$(document).on('click', '.fa', function(){
  $('[data-toggle="popover"]').popover('toggle');
});

handlebar创建了元素,但没有将其添加到DOM中。

所以在你的代码中

代码语言:javascript
复制
// 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');
});
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42597855

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档