jQuery拖放 - 如何获取被拖动的元素

jQuery drag and drop - how to get at element being dragged(jQuery拖放 - 如何获取被拖动的元素)
本文介绍了jQuery拖放 - 如何获取被拖动的元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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?

我想在 div 中获取图像的 id.拖动以下元素:

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) { }
});

我尝试了各种 ui.id 等似乎不起作用.

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

推荐答案

不是ui.draggable吗?

Is it not the ui.draggable?

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

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

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

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拖放 - 如何获取被拖动的元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Update another component when Formik form changes(当Formik表单更改时更新另一个组件)
Formik validation isSubmitting / isValidating not getting set to true(Formik验证正在提交/isValiating未设置为True)
React Validation Max Range Using Formik(使用Formik的Reaction验证最大范围)
Validation using Yup to check string or number length(使用YUP检查字符串或数字长度的验证)
Updating initialValues prop on Formik Form does not update input value(更新Formik表单上的初始值属性不会更新输入值)
password validation with yup and formik(使用YUP和Formick进行密码验证)