如何获取丢弃的项目的id在drop事件jquery [英] How to get the dropped item's id on drop event jquery

查看:157
本文介绍了如何获取丢弃的项目的id在drop事件jquery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我把某些东西放到jquery droppable上时,我想得到丢弃的项目的id。当我这样做:

When I drop something to jquery droppable, I want to get the dropped items' id. When I did it like this:

$("#here").droppable({
        tolerance: 'fit',
        accept: ".one",
         drop: function(){
            id = $(this).attr("id");
            alert (id);
        }
    });

当然会提醒可放下的的I​​D在这里。如何选择删除的div的id?

it of course alerted the id of the droppable here. How can I select the id of the dropped div?

推荐答案

更改drop函数以获取两个参数:event,ui

Change your drop function to take two arguments: event, ui

function(event,ui){
    var draggable = ui.draggable;
    var id = draggable.attr("id");
}

正在删除的draggable由ui.draggable

The draggable that is being dropped is represented by ui.draggable

在jquery ui docs中找到可下载的文件。

Found in the jquery ui docs for droppable.

这篇关于如何获取丢弃的项目的id在drop事件jquery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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