jQuery 工具提示:remove() 遇到问题
我正在使用 jQuery 工具提示 插件。
我有这样的 HTML:
<li class="term ui-droppable">
<strong>Fall 2011</strong>
<li class="course ui-draggable">Biological Statistics I<a class="remove-course-button" href="">[X]</a></li>
<div class="term-meta-data">
<p class="total-credits too-few-credits">Total credits: 3</p>
<p class="median-GPA low-GPA">Median Historical GPA: 2.00</p>
</div>
</li>
我想删除 .course
元素。因此,我将一个点击处理程序附加到 :
function _addDeleteButton(course, term) {
var delete_button = $('<a href="" class="remove-course-button" title="Remove this course">[X]</a>');
course.append(delete_button);
$(delete_button).click(function() {
course.remove();
return false;
}).tooltip();
}
就附加点击处理程序而言,这一切都工作正常。但是,当调用 course.remove()
时,Firebug 会在 tooltip.js 中报告错误:
Line 282
tsettings is null
if ((!IE || !$.fn.bgiframe) && tsettings.fade) {
我做错了什么?如果链接附有工具提示,我是否需要专门将其删除?
更新:删除.tooltip()
解决问题。我想保留它,但这让我怀疑我在这里使用 .tooltip()
是不正确的。
I'm using a jQuery tooltip plugin.
I have HTML like this:
<li class="term ui-droppable">
<strong>Fall 2011</strong>
<li class="course ui-draggable">Biological Statistics I<a class="remove-course-button" href="">[X]</a></li>
<div class="term-meta-data">
<p class="total-credits too-few-credits">Total credits: 3</p>
<p class="median-GPA low-GPA">Median Historical GPA: 2.00</p>
</div>
</li>
I want to remove the .course
element. So, I attach a click handler to the <a>
:
function _addDeleteButton(course, term) {
var delete_button = $('<a href="" class="remove-course-button" title="Remove this course">[X]</a>');
course.append(delete_button);
$(delete_button).click(function() {
course.remove();
return false;
}).tooltip();
}
This all works fine, in terms of attaching the click handler. However, when course.remove()
is called, Firebug reports an error in tooltip.js:
Line 282
tsettings is null
if ((!IE || !$.fn.bgiframe) && tsettings.fade) {
What am I doing wrong? If the link has a tooltip attached, do I need to remove it specially?
UPDATE: Removing .tooltip()
solve the problem. I'd like to keep it in, but that makes me suspect that my use of .tooltip()
is incorrect here.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
.tooltip()
插件有几个附加到元素的处理程序,即mouseover
、mouseout
和click
>。如果要删除该元素,只需.unbind()
all需要注意的另一个更改是
delete_button
已经是一个 jQuery 对象,再次将其包装在$()
中 只是克隆它 :)发生错误是因为它试图在元素被删除后获取并使用它的设置数据虽然
.remove()
通过jQuery.data()
,其中 jQuery 从缓存中删除数据。这种方法只是阻止所有这些工具提示处理程序再次运行,因此数据消失(应该如此)并不重要,因为现在没有任何东西会寻找它。The
.tooltip()
plugin has several handlers that attach to the element, namely onmouseover
,mouseout
, andclick
. If you're removing the element, just.unbind()
all these events so they don't run, like this:One other change to note is that
delete_button
is already a jQuery object, wrapping it in$()
again just clones it :)The error happens because it's trying to fetch and use it's settings data off the element after it's been though
.remove()
viajQuery.data()
, in which jQuery removes it's data from the cache. This approach this just prevents all those tooltip handlers from running again, so it won't matter that the data's gone (as it should be), because nothing will be looking for it now.我遇到了同样的问题,最终不得不延迟 .remove() 的调用以防止出现错误。因此,类似以下内容可能适合您:
I had this same issue and ended up having to delay the call of .remove() to prevent the error. So something like the following may work for you: