[英]Dynamic popover/tooltip via Bootstrap with flask & python
I'm trying to create dynamically generated tooltip/popover content for a site using bootstrap (3.1), flask and python. 我正在尝试使用bootstrap(3.1),flask和python为网站创建动态生成的工具提示/弹出窗口内容。
I have hyper-linked items in a table. 我在表中有超链接项目。 When I mouse over those hyperlinks, I want a tooltip to appear;
当我将鼠标悬停在那些超链接上时,我希望出现一个工具提示。 when the user clicks on the hyperlink I want them to go to the individual item page.
当用户单击超链接时,我希望他们转到单个项目页面。 Code (shortened for brevity):
代码(为简洁起见,简称):
<table>
<thead>
<tr>
<th>Item</th>
<th>Quantity</th>
<th>Color</th>
</tr>
</thead>
<tbody>
<tr>
<td>{% include 'itemlink.html' %}</td>
<td>12</td>
<td>red</td>
</tbody>
</table>
then in itemlink.html: 然后在itemlink.html中:
<a href="{{linkitem.get_url()}}" class="itemlink" data-item-id="{{linkitem.id}}">
<img src="{{linkitem.image}}" alt="Item {{linkitem.id}}" class="smallicon" />
{{linkitem|safe}}
</a>
Next: the content of what I want to be in the popover/tooltip box: 下一步:我要在弹出框/工具提示框中显示的内容:
<div id="item_{{boxitem.id}}" class="itembox">
<div class="itemimage">
<img src="{{boxitem.image}}" alt="{{boxitem.name}}" title="{{boxitem.get_title()}}" />
</div>
<div class="iteminfo">
<div class="itemtitle">
{{boxitem.get_title()}}
</div>
<div class="itemdesc">
{% autoescape off %}{{boxitem.get_desc()}}{% endautoescape %}
</div>
</div>
</div>
I put this in a script on my page: 我将其放在页面上的脚本中:
<script>
$(document).ready(function(){
$('#item_{{item.id}}').popover({
html: true,
placement: 'right',
trigger: 'hover',
selector: '[rel="popover"]'
});
});
</script>
I'm wondering if this part of the script is even possible? 我想知道脚本的这一部分是否可行?
$('#item_{{item.id}}').popover({
EDIT TO ADD: (it's not, it threw a server error) 编辑添加:(不是,它引发了服务器错误)
EDIT again: It had to be 再次编辑:必须是
$('.itembox#item_'+$(this).data(itemID')).popover
On what element should I add the rel=popover? 我应该在哪个元素上添加rel = popover?
I would give each item a static class like tool tip or give the table an id and use jQuery selector on the element in the table for the hover event. 我会给每个项目一个静态类,如工具提示,或者给表一个ID并在表中的元素上使用jQuery选择器进行悬停事件。
$(document).ready(function(){ $('td.tooltip').popover({ html: true, placement: 'right', trigger: 'hover', selector: '[rel="popover"]' }); })
; $(document).ready(function(){ $('td.tooltip').popover({ html: true, placement: 'right', trigger: 'hover', selector: '[rel="popover"]' }); })
;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.