我对这个 jQuery 工具提示行为做错了什么?
(编辑)当前行为是悬停时不显示工具提示。不是默认的 html 标题或 jquery 工具提示(/编辑)
我在网页上有一个日历。当一天有事件并将鼠标悬停在其上时,将显示 html 标题属性,其中包含以逗号分隔的事件名称。当一天有 20 个事件时,这将开始看起来很难看,所以我想使用 jQuery 使此显示不同。这是我用于显示工具提示的代码(我在使用 $ for jQuery 时遇到了问题,因为我不明白页面上其他 jQuery 脚本之间的冲突内容,并且将其全部键入似乎可以正常工作):
jQuery(function(){
var tip = jQuery("#tip");
//on hover of links with a class of "eventful"
jQuery(".eventful a").hover(function(e){
//pull the title attribute into variable "tip"
tip.text(jQuery(this).attr("title"));
//make the default title blank
jQuery(this).attr("title", "");
//place the new title with css
tip.css("top",(e.pageY+5)+"px")
.css("left",(e.pageX+5)+"px")
.fadeIn("slow");
}, function() {
//on mouse out remove
jQuery("#tip").fadeOut("fast");
//replace the default title
jQuery(this).attr("title", tip.html());
});
});
这不起作用,所以我不确定我在那里做错了什么。但是在显示要显示的工具提示后,我需要更改多个逗号分隔事件的显示方式,最好更改为无序列表。我下面有这个片段,它可能会或可能不会将项目分隔成数组,在每个逗号处断开字符串:
var titleArray = $(".eventful").attr("title").split("," );
如果这确实有效,我不知道如何合并它,并将其放入 ul 中。非常感谢您对此的帮助!
(edit) current behavior is no tooltip showing on hover. not the default html title or the jquery tooltip(/edit)
I have a calendar on a webpage. When a day has an event and you hover over it, the html title attribute displays containing the event names separated by commas. This is going to start looking ugly when there's 20 events on a single day, so I want to make this display differently using jQuery. Here's my code for showing the tooltip (i've run into problems using $ for jQuery because I don't understand the conflict stuff between other jQuery scripts on the page and typing it all out seems to just work):
jQuery(function(){
var tip = jQuery("#tip");
//on hover of links with a class of "eventful"
jQuery(".eventful a").hover(function(e){
//pull the title attribute into variable "tip"
tip.text(jQuery(this).attr("title"));
//make the default title blank
jQuery(this).attr("title", "");
//place the new title with css
tip.css("top",(e.pageY+5)+"px")
.css("left",(e.pageX+5)+"px")
.fadeIn("slow");
}, function() {
//on mouse out remove
jQuery("#tip").fadeOut("fast");
//replace the default title
jQuery(this).attr("title", tip.html());
});
});
and that's not working, so I'm not sure what i'm doing wrong there. but after I get the tooltip to display, I need to change the way the multiple, comma separated events are shown, preferably changed into an unordered list. I've got this snippet below that may or may not separate the items into an array, breaking the string off at each comma:
var titleArray = $(".eventful").attr("title").split(",");
if that does work, I'm not sure how to incorporate it, and get it into a ul. many thanks in advance for help on this!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Tip div 应该有
position:absolute
样式 &它的 z-index 应该大于页面中的其他元素。添加jQuery("#tip").css('z-index',somehighvalue)
tip div should have
position:absolute
style & it's z-index should be greater then other elements in the page. AddjQuery("#tip").css('z-index',somehighvalue)