我有一个搜索结果列表,我希望每个搜索结果能够在工具提示中显示有关结果的更多信息.
当我翻转每个元素时,我已经得到了一个qTip工具提示,但是我不明白如何将自定义内容放入工具提示中以获得每个结果.
我想这主要是因为我非常有限的jQuery知识.
在旧式JavaScript中,我会传递一个变量,该变量是附加到<a>标签的函数调用中的工具提示内容.由于<a>jQuery工具提示的标签中没有写入函数调用,因此现在看来这不是现在的方法.
目前我头脑中有这个:
<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'
}
}
});
});
Run Code Online (Sandbox Code Playgroud)
然后身体有<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>
Run Code Online (Sandbox Code Playgroud)
但是这没有显示,我不知道如何为每个工具提示创建一个特定的HTML块.
我的方法有误吗?
我是否应该创建包含具有单独ID的自定义内容的所有单个工具提示,然后选择这些ID并显示或类似的东西?
您可以省略content属性以使用<a>标记的标题:
// use title attribute
$(".tooltip").qtip({
position: {
corner: {
target: 'topRight',
tooltip: 'bottomLeft'
}
}
});
Run Code Online (Sandbox Code Playgroud)
或者您可以使用jquery选择器.例如:
// use jquery selector
$(".tooltip2").each(function() {
var content = $($(this).attr("href")).html();
$(this).qtip({
content: content,
position: {
corner: {
target: 'topRight',
tooltip: 'bottomLeft'
}
}
});
});
Run Code Online (Sandbox Code Playgroud)
示例:jsFiddle
| 归档时间: |
|
| 查看次数: |
8791 次 |
| 最近记录: |