如标题所示,如何使用jQuery在鼠标悬停时显示工具提示消息?
如标题所示,如何使用jQuery在鼠标悬停时显示工具提示消息?
Answers:
工具提示插件可能无法满足您的需求。只需将“ title”属性设置为您希望在工具提示中显示的文本即可。
$("#yourElement").attr('title', 'This is the hover-over text');
prop代替。$("#yourElement").prop('title', 'This is the hover-over text');
以下操作将像一个魅力一样(假设您在div / span / table / tr / td / etc中有"id"="myId")
$("#myId").hover(function() {
$(this).css('cursor','pointer').attr('title', 'This is a hover text.');
}, function() {
$(this).css('cursor','auto');
});
作为一项补充,.css('cursor','pointer')将在悬停时更改鼠标指针。
您可以仅使用css来执行此操作,而无需使用任何jQiuery。
<a class="tooltips">
Hover Me
<span>My Tooltip Text</span>
</a>
<style>
a.tooltips {
position: relative;
display: inline;
}
a.tooltips span {
position: absolute;
width: 200px;
color: #FFFFFF;
background: #000000;
height: 30px;
line-height: 30px;
text-align: center;
visibility: hidden;
border-radius: 6px;
}
a.tooltips span:after {
content: '';
position: absolute;
top: 100%;
left: 35%;
margin-left: -8px;
width: 0;
height: 0;
border-top: 8px solid #000000;
border-right: 8px solid transparent;
border-left: 8px solid transparent;
}
a:hover.tooltips span {
visibility: visible;
opacity: 0.8;
bottom: 30px;
left: 50%;
margin-left: -76px;
z-index: 999;
}
</style>
title="My tooltip属性与元素本身一起使用