jQuery拖放 - 如何获取元素被拖动 [英] jQuery drag and drop - how to get at element being dragged

查看:124
本文介绍了jQuery拖放 - 如何获取元素被拖动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用jQuery库来实现拖放。



如何获取被删除的元素?



我想得到div中的图像的id。拖动以下元素:

 < div class =block> 
< asp:Image ID =Image9AlternateText =10/12/2008 - RetinaWidth = 81 Height = 84 ImageUrl =〜/ uploads / ImageModifier / retina.jpgrunat = server />
< / div>

我从他们的示例中删除了标准的功能:



$ $ $ $ $ $ $$$$$$$$ b hoverClass:'droppable-hover',
drop:function(ev,ui){}
});

我已尝试过各种 ui.id

解决方案

这不是ui.draggable吗?



如果你去这里(在Firefox中,假设你有firebug),并看着firebug控制台,你会看到我正在做一个console.dir的ui.draggable对象,这是被拖动的



http://jsbin.com/ixizi



因此,在drop函数中需要的代码是

  drop:function ,ui){
//获取id
//ui.draggable.attr('id')或ui.draggable.get(0).id或ui.draggable [0] .id
console.dir(ui.draggable)
}


I am using the jQuery library to implement drag and drop.

How do I get at the element that is being dragged when it is dropped?

I want to get the id of the image inside the div. The following element is dragged:

<div class="block">
    <asp:Image ID="Image9" AlternateText="10/12/2008 - Retina" Width=81 Height=84 ImageUrl="~/uploads/ImageModifier/retina.jpg" runat=server />
</div>

I have the standard dropped function from their example:

$(".drop").droppable({
                 accept: ".block",
                 activeClass: 'droppable-active',
                 hoverClass: 'droppable-hover',
                 drop: function(ev, ui) { }
});

I have tried various ui.id etc. which doesn't seem to work.

解决方案

Is it not the ui.draggable?

If you go here (in Firefox and assuming you have firebug) and look in the firebug console youll see I am doing a console.dir of the ui.draggable object which is the div being dragged

http://jsbin.com/ixizi

Therefore the code you need in the drop function is

       drop: function(ev, ui) {
                 //to get the id
                 //ui.draggable.attr('id') or ui.draggable.get(0).id or ui.draggable[0].id
                 console.dir(ui.draggable)  
       }

这篇关于jQuery拖放 - 如何获取元素被拖动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆