jQuery:拖放:找到目标的id [英] jQuery : drag and drop : find the id of the target

查看:81
本文介绍了jQuery:拖放:找到目标的id的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个拖放应用程序。我有一个可以在文档中拖动的DIV,文档中还有一些其他的div,我可以将一个div拖到其他div,但是我怎样才能找到拖放DIV的div的id,

I am developing a drag and drop app. I have a DIV that is draggable along the document and there are some other divs in the document, I can drag one div to other divs, but how can I find the id of the div to which I dropped the dragging DIV,

我只是想知道目标DIV的id后再放置另一个DIV。

I just want to know the id of the target DIV after placing another DIV over it.

谢谢

推荐答案

您应该可以从 this.id 获取目标的ID在事件函数内部(演示

You should be able to get the ID of the target from this.id from inside the event functions (demo)

$(".droppable").droppable({
    drop: function(event, ui) {
        $(this).addClass("ui-state-highlight").find("p").html("Dropped in " + this.id);
    },
    over: function(event, ui) {
        $('.display').html( this.id );
    }
});

更新了演示,以明确 this.id 适用于任何活动。

Updated demo to make it clear that this.id works in any of the events.

这篇关于jQuery:拖放:找到目标的id的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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