javascript - jQuery : drag and drop : find the id of the target

标签 javascript jquery

我正在开发一个拖放应用程序。我有一个可以沿着文档拖动的 DIV,并且文档中还有一些其他的 div,我可以将一个 div 拖到其他 div,但是如何找到我将拖动的 DIV 拖放到的 div 的 id,

我只想知道在放置另一个 DIV 之后目标 DIV 的 ID。

谢谢

最佳答案

您应该能够从事件函数 (demo) 中的 this.id 获取目标的 ID

$(".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 );
    }
});

Updated demo明确 this.id 适用于任何事件。

关于javascript - jQuery : drag and drop : find the id of the target,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3943868/

相关文章:

javascript - 实习生 cucumber 插件错误: A plugin named "cucumber" has not been registered

javascript - 使用jquery连续监控3个文本输入字段

jquery - 如何在初始化后设置jqueryui datepicker minDate?

javascript - ajax 回调后如何从主函数返回 false?

javascript - -- 存储我在 React 中使用的 DOM 元素,这样我就不会一直拉取它们?

javascript - 无法访问类构造函数中设置的变量

javascript - $(document).ready 中的 jquery 的 removeAttr 函数不起作用

javascript - 刷新表格而不刷新整个页面以显示更新的数据

javascript - JQuery Tablesorter - 通过单击链接进行过滤

javascript - 不渲染组件 onClick