使用 jquery UI droppable 和 livequery 时出现问题!

发布于 2024-08-02 17:07:47 字数 306 浏览 3 评论 0原文

我有一些要删除的元素的代码

var $tab_items = $("ul:first li",$tabs).droppable{ opportunity: 'touch' ,....

工作正常,但问题是当我通过 ajax 或 javascript 加载另一个按钮时, 不起作用,因为新元素没有对此事件的绑定。

在其他类似的情况下,我找到了使用 livequery (事件委托)的解决方案,但在这里这是不可能的,因为我不想附加函数,我想在第一行代码上附加相同的函数。

有什么解决方案比在每次新对象加载后制作 dropabble 更好吗?

I have this code for some elements to be dropped

var $tab_items = $("ul:first li",$tabs).droppable{ tolerance: 'touch' ,....

and it´s work ok, but the problem it´s when I load another button by ajax or by javascript,
don´t work because the new element don´t have binding for this event.

In other similar situation I found a solution using livequery (event delegation), but here it´s imposibble because I don´t want to attach a function, I want to attach the same that on the first line code.

Any solution better than making dropabble after every new object load?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

眼眸里的那抹悲凉 2024-08-09 17:07:47

只需在 ajax 成功回调中添加处理程序即可。

$.ajax({
   url: ...
   ...
   success: function(data) {
        $('<li>....</li>').droppable( { tolerance: 'touch', ... } )
                          .appendTo( '#tabs ul:first' );
        ...
   }
   ...
});

Just add the handler in your ajax success callback.

$.ajax({
   url: ...
   ...
   success: function(data) {
        $('<li>....</li>').droppable( { tolerance: 'touch', ... } )
                          .appendTo( '#tabs ul:first' );
        ...
   }
   ...
});
偏爱自由 2024-08-09 17:07:47

这可能是错误的预感,但您可能想看看:
http://docs.jquery.com/UI/Sortable

This might be a wrong hunch but you might want to look at:
http://docs.jquery.com/UI/Sortable

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文