我试图创建一个列表里面的工具提示,这个列表应该是可选的,所以我使用下一个wbepage的代码:http://3nhanced.com/javascript/simple-tooltip-powered-by-jquery/ 来创建我的工具提示,但是当我使用下一个代码创建可选项目:我的jquery选择器错了吗?
$(document).ready(function() {
$('.toolTip').hover(
function() {
this.tip = this.title;
console.log($(this));
$(this).append(
'<div class="toolTipWrapper">'
+'<div class="toolTipTop"></div>'
+'<div class="toolTipMid">'
+'<ul id="selectable">'
+'<li class="ui-widget-content">Item</li>'
+'<li class="ui-widget-content">Item</li>'
+'</ul>'
+'</div>'
+'<div class="toolTipBtm"></div>'
+'</div>'
);
this.title = "";
this.width = $(this).width();
$(this).find('.toolTipWrapper').css({left:this.width-22})
$('.toolTipWrapper').fadeIn(300);
},
function() {
$('.toolTipWrapper').fadeOut(100);
$(this).children().remove();
this.title = this.tip;
}
);
$("#selectable").selectable({
stop: function() {
var $item2 = $(this),
$target = $(event.target);
console.log($target);
var result = $("#select-result").empty();
$(".ui-selected", this).each(function() {
var index = $("#selectable li").index(this);
result.append(" #" + (index + 1));
});
}
});
});
有没有人有一个想法,为什么它不工作?每个人都可以看到;在使用可选功能之前,先完成toolltip创建。 在此先感谢。
有点偏题:你每次徘徊/关闭某物时,是否在创建/附加和销毁div?对于div已经存在并隐藏/显示它不是更容易吗? – 2012-04-20 21:55:06