动态弹出/工具提示通过Bootstrap with flask&蟒蛇

时间:2014-02-27 00:18:40

标签: javascript jquery python twitter-bootstrap twitter-bootstrap-3

我正在尝试使用bootstrap(3.1),flask和python为站点创建动态生成的工具提示/弹出窗口内容。

我在表格中有超链接的项目。当我将鼠标悬停在那些超链接上时,我想要一个工具提示出现;当用户点击超链接时,我希望他们转到单个项目页面。代码(为简洁起见缩短):

<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>

然后在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>

下一篇:我想在popover / tooltip框中输入的内容:

<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>

我把它放在我页面上的脚本中:

<script>
  $(document).ready(function(){
   $('#item_{{item.id}}').popover({
     html: true,
     placement: 'right',
     trigger: 'hover',
     selector: '[rel="popover"]'
   });
  });
 </script>

我想知道脚本的这部分是否可能?

  $('#item_{{item.id}}').popover({

编辑添加:(不是,它引发了服务器错误)
再次编辑:它必须是

$('.itembox#item_'+$(this).data(itemID')).popover


我应该在什么元素上添加rel = popover?

1 个答案:

答案 0 :(得分:0)

我会给每个项目一个静态类,比如工具提示或给表格一个id,并在表格中的元素上使用jQuery选择器来表示悬停事件。   $(document).ready(function(){ $('td.tooltip').popover({ html: true, placement: 'right', trigger: 'hover', selector: '[rel="popover"]' }); });