淡出并删除表格行
我知道这个问题之前已经被问过,但我似乎遇到了与之前解决的问题不同的问题。我有一个表,我希望每一行都有一个删除链接,该链接会淡出表行,然后从 DOM 中删除表行。我的第一个问题是我无法让 jQuery fadeOut 效果在表行上工作,并且发现您必须在行的 td 元素上实际调用 fadeOut。所以,这是我的 jJavascript:
$('span.deleteItem').live('click', function() {
$(this).closest('tr').find('td').fadeOut('fast',
function(){
$(this).parents('tr:first').remove();
});
return false;
});
span 元素位于 td 内,因此当单击它时我会找到最接近的 tr 元素,然后将 fadeOut 函数放在其每个 td 元素上。这很好用。
问题在于,在回调函数中,“this”实际上引用的是 window 元素,而不是隐藏的单个 td 元素。根据我的理解,“this”应该引用淡出的元素。
有什么想法吗?
I know this question has been asked before but I seem to have a different problem than has been addressed before. I have a table and I would like each row to have a delete link that fades the table row out and then removes the table row from the DOM. My first problem was that I couldn't get the jQuery fadeOut effect to work on table rows and found that you have to actually call fadeOut on the row's td elements. So, here is my jJavascript:
$('span.deleteItem').live('click', function() {
$(this).closest('tr').find('td').fadeOut('fast',
function(){
$(this).parents('tr:first').remove();
});
return false;
});
The span element lives inside a td so I find the closest tr element when it is clicked, and then fall the fadeOut function on each of its td elements. This works great.
The problem is that in the callback function, 'this' is actually referencing the window element not the individual td element that was hidden. From my understanding 'this' was supposed to reference the element that was faded out.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
获取“this”引用并将其传递:
Grab the "this" reference and pass it on:
我认为这就是您正在寻找的:
编辑:我认为 Opatut 是正确的,如他的 jsFiddle。
I think this is what you are looking for:
EDIT: I think Opatut is right, as show in his jsFiddle.