jquery close() 选择
我在运行删除元素功能时遇到问题。
我有这个函数:
//Remove an Item From Any Group
function deleteItem (selector) {
$(selector).closest("li").fadeOut(500, function() {
$(selector).closest("li").remove();
});
}
来调用它
$("a.delete").live('click', function() {
deleteItem("li span.delete a.delete");
});
然后用这个 HTML
<ul>
<li><img src="" width="40" height="40" class="image"/><span><a href="#">Drinkers Pub</a></span><span class="delete"><a href="javascript:;" class="delete">delete</a></span></li>
<li><img src="" width="40" height="40" class="image"/><span><a href="#">Drinkers Pub</a></span><span class="delete"><a href="javascript:;" class="delete">delete</a></span></li>
<li><img src="" width="40" height="40" class="image"/><span><a href="#">Drinkers Pub</a></span><span class="delete"><a href="javascript:;" class="delete">delete</a></span></li>
</ul>
:问题是它只是删除列表中的第一个 LI,无论哪个链接。 我认为最接近的选择了事件中最接近的元素。在这种情况下,单击删除按钮。
我缺少什么?
I am having issues getting my remove element function working.
I have this function:
//Remove an Item From Any Group
function deleteItem (selector) {
$(selector).closest("li").fadeOut(500, function() {
$(selector).closest("li").remove();
});
}
Then this to call it,
$("a.delete").live('click', function() {
deleteItem("li span.delete a.delete");
});
With this HTML:
<ul>
<li><img src="" width="40" height="40" class="image"/><span><a href="#">Drinkers Pub</a></span><span class="delete"><a href="javascript:;" class="delete">delete</a></span></li>
<li><img src="" width="40" height="40" class="image"/><span><a href="#">Drinkers Pub</a></span><span class="delete"><a href="javascript:;" class="delete">delete</a></span></li>
<li><img src="" width="40" height="40" class="image"/><span><a href="#">Drinkers Pub</a></span><span class="delete"><a href="javascript:;" class="delete">delete</a></span></li>
</ul>
The problem is it is only removing the first LI in the list no matter which link.
I thought closest picks the closest element from the event. IN this case the click of the delete button.
What am I missing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您向 deleteItem 函数传递一个选择器,该选择器可以获取所有删除链接。
你会想要更多这样的东西。
You are passing the deleteItem function a selector that gets you all of the delete links.
You'll want something more like this.