简体   繁体   English

twitter bootstrap工具提示在js模板中不起作用

[英]twitter bootstrap tooltip not working in js template

I ma using twitter bootstrap tooltip functionality which works fine in gsp header texts. 我正在使用twitter引导工具提示功能,该功能在gsp标头文本中可以正常工作。 Now I want to add bootstrap tooltip on id="tooltipcheck". 现在,我想在id =“ tooltipcheck”上添加引导工具提示。 If I write title="{{data}}" then I could see the tooltip but bootstrap tooltip does not seem to work here. 如果我写title =“ {{data}}”,那么我可以看到工具提示,但是引导工具提示似乎在这里不起作用。 Is there any issue with js template or there is something else? js模板有任何问题还是其他问题?

<script id="myTemplate" type="text/x-handlebars-template">
<div class="row">
    <div class="span4" id="tooltipcheck" data-placement="bottom" data-toggle="tooltip"  data-original-title="{{data}}">{{data}} </div>
</div>

I am calling tooltip like this. 我这样称呼工具提示。

      <script>

jQuery(function ($) {
    $("#tooltipcheck").tooltip('show');

});

You can't set the ID of an element in a template because ID's need to be unique. 您无法设置模板中元素的ID,因为ID必须是唯一的。 Try changing tooltipcheck to a class instead: 尝试将tooltipcheck更改为一个类:

<div class="span4 tooltipcheck" data-placement="bottom" data-toggle="tooltip" data-original-title="{{data}}">{{data}} </div>

And then initialize your tooltips using the class: 然后使用该类初始化您的工具提示:

$(".tooltipcheck").tooltip('show');

The tooltips will need to be initialized after handlebars has parsed the template and generated your markup, or else the tooltips won't have any elements to bind to. 在车把解析了模板并生成标记后,将需要初始化工具提示,否则工具提示将没有任何元素要绑定。

since you are working with dynamic elements, after the elements are added to the dom you need to initialize the tooltip for the new elements 由于您正在使用动态元素,因此在将元素添加到dom后,您需要为新元素初始化工具提示

Ex: 例如:

var html = // html from template
var el = $(html).appendTo('somele');
el.find('<tooltip-element>').tooltip('show');

Also since you are using a template I'm assuming there will be multiple instances of the template in the page, so do not use id inside the template since in dom an id should be present only once 另外,由于您使用的是模板,所以我假设页面中会存在该模板的多个实例,因此请勿在模板内使用id ,因为在dom中,一个id仅应出现一次

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

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