每个qTip工具提示的自定义内容

时间:2011-03-24 13:00:30

标签: jquery qtip

我有一个搜索结果列表,对于每个搜索结果,我希望能够在工具提示中显示有关结果的更多信息。

当我翻转每个元素时,我已经得到了一个qTip工具提示,但我不明白如何在每个结果的工具提示中获取自定义内容。

我想这主要是因为我非常有限的jQuery知识。

在旧式JavaScript中,我会传递一个变量,该变量是附加到<a>标签的函数调用中的工具提示内容。因为jQuery工具提示的<a>标签中没有写入函数调用,所以现在看来​​这不是现在的方法。

目前我的头脑中有这个:

<script type="text/javascript" 
       src="/assets/templates/unaexchange/js/jquery.qtip-1.0.0.min.js"></script>

<script>
$(document).ready(function() {
$(".tooltip").qtip({
   content: 'this is the content',
   position: {
      corner: {
         target: 'topRight',
         tooltip: 'bottomLeft'
      }
   }
});
});

然后身体有<a class="tooltip">Link</a>然后我有标准:

<div class="qtip qtip-stylename">
  <div class="qtip-tip" rel="cornerValue"></div>
  <div class="qtip-wrapper">
    <div class="qtip-borderTop"></div> 
             <!-- Only present when using rounded corners-->
    <div class="qtip-contentWrapper">
        <div class="qtip-title"> 
             <!-- All CSS styles...-->
        <div class="qtip-button"></div> 
             <!-- ...are usually applied...-->
    </div>
    <div class="qtip-content">an attempt at standard content ?></div> 
             <!-- ...to these three elements!-->
  </div>
  <div class="qtip-borderBottom"></div> 
             <!-- Only present when using rounded corners-->
  </div>
</div>

但是这没有显示,我不知道如何为每个工具提示创建一个特定的HTML块。

我的方法有误吗?

我是否应该创建包含具有单独ID的自定义内容的所有单个工具提示,然后选择这些ID并显示或类似的东西?

2 个答案:

答案 0 :(得分:7)

您可以省略content属性以使用<a>标记的标题:

// use title attribute
$(".tooltip").qtip({
    position: {
        corner: {
            target: 'topRight',
            tooltip: 'bottomLeft'
        }
    }
});

或者您可以使用jquery选择器。例如:

// use jquery selector
$(".tooltip2").each(function() {

    var content = $($(this).attr("href")).html();

    $(this).qtip({
        content: content,
        position: {
            corner: {
                target: 'topRight',
                tooltip: 'bottomLeft'
            }
        }
    });
});

示例此处:jsFiddle

答案 1 :(得分:0)

使用您想要的工具提示内容为每个DOM元素添加title属性。如,

<span class='tooltip' title='This will show up as a tooltip'>Whatever your markup happens to be</span>

<a class='tooltip' href='#' title='Another tooltip'>Some link</a>

title属性为standard in HTML 5 for all DOM elements