gpt4 book ai didi

jquery - 如何使用jQuery qTip?

转载 作者:行者123 更新时间:2023-12-03 21:31:23 25 4
gpt4 key购买 nike

有人可以向我展示一个简单的示例,说明如何设置和使用 qTip jQuery 插件,以便在我将鼠标悬停在图像上的位置的左下角显示工具提示。

我尝试遵循 the qTip site 中的演示/示例但似乎无法让它发挥作用。

我不确定是否需要在文档中包含 HTML 结构,如果需要,我应该将其放在哪里?

这个插件是否还需要某种 CSS 文件?

最佳答案

我认为问题源于新的 qTip 版本和 jQuery 之间的不兼容。

我花了最后一个小时用 qTip 测试代码,试图找出为什么我的代码拒绝工作,并在查看了 forums 后为了看看我是否能找到类似的问题,我注意到线程中的以下代码工作正常,但如果将其与更新版本的 jQuery 交换,则会产生错误。

<html>
<head>
<script type="text/javascript" src="jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="jquery.qtip-1.0.0-rc3.min.js"></script>


<script type="text/javascript">
$( document ).ready( function( ) {
$.fn.qtip.styles.tooltipDefault = {
background : '#132531',
color : '#FFFFFF',
textAlign : 'left',
border : {
width : 2,
radius : 4,
color : '#C1CFDD'
},
width : 220
}

// we are going to run through each element with the classRating class
$( '.classRating' ).each( function( ) {
var rating = $( this ).attr( 'rating' );

// the element has no rating tag or the rating tag is empty
if ( rating == undefined || rating == '' ) {
rating = 'I have not yet been rated.';
}
else {
rating = 'The rating for this is ' + rating + '%';
}

// create the tooltip for the current element
$( this ).qtip( {
content : rating,
position : {
target : 'mouse'
},
style : 'tooltipDefault'
} );
} );
} );

</script>
</head>
<body>
<div id="SomeID1" class="classRating" rating="73">I have a rating</div>
<div id="SomeID2" class="classRating" rating="66">I have a rating</div>
<div id="SomeID3" class="classRating" rating="">I have a rating but it is empty</div>
<div id="SomeID4" class="classRating">I dont have a rating</div>
</body>
</html>

我下载了jQuery 1.3.2 from the Google Code website这个例子现在非常适合我。我很快就会开始根据我的需要定制此代码,看看是否存在任何其他问题,但对于仍然遇到此问题的任何人,我希望这篇文章有用。

<小时/>

编辑:看起来是版本不兼容问题。文档网站上的这个简单代码现在可以完美地与这些相同的版本配合使用。希望这对您有帮助!

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

</head>
<body>
<a href="#" title="Hello World" class="example">Test</a>
<script type="text/javascript" src="jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="jquery.qtip-1.0.0-rc3.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
// By suppling no content attribute, the library uses each elements title attribute by default
$('a[href][title]').qtip({
content: {
text: false // Use each elements title attribute
},
style: 'cream' // Give it some style
});

// NOTE: You can even omit all options and simply replace the regular title tooltips like so:
// $('#content a[href]').qtip();
});
</script>
</body>
</html>

编辑 2: qTip 的新版本正在开发中,因此可能值得等待,但是如果您想将 qTip 与最新版本的 jQuery 一起使用,那么您可以下载一个nightly builds的对于 qTip。使用上面的示例,我将两个脚本替换为最新的 jQuery (1.4.2) 和最新的夜间构建,它似乎可以工作。

关于jquery - 如何使用jQuery qTip?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2950004/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com