使用dragula javascript获取已删除div的ID [英] get id of dropped div using dragula javascript

查看:113
本文介绍了使用dragula javascript获取已删除div的ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用dragula.js拖放来更新c3.js图表​​,但是我不知道如何获取被拖动到新容器中的div的ID.我的html是这样的:

I am trying to update a c3.js chart using drag and drops with dragula.js, but I don't know how to get the id of the div that is dragged into a new container. My html is something like this:

<div id="collapse1" class="panel-collapse collapse">
    <div id="color1" class="form-inline">1</div>
    <div id="color2" class="form-inline">2</div>
    <div id="color3" class="form-inline">3</div>
</div>
<div id="collapse2" class="panel-collapse collapse">

</div>

并且我正在使用dragula.js进行拖放:

and I'm using dragula.js to drag and drop:

dragula([collapse1,collapse2]);

我对jquery确实很陌生,但遵循这个问题,访问我尝试执行的操作中放入collapse2<div>的ID:

I am really new to jquery, but following this question, to access the id of the <div> dropped into collapse2 in I was trying to do something like this:

alert($("#collapse1.collapse2 div:first").attr("id"));

但没有结果.任何帮助将不胜感激

But no results. Any help would be really appreciated

推荐答案

Dragula具有三个元素,一个是Source Div,Target Div及其关联的元素.以下方法对我而言具有魅力,但我不使用具有版本问题的get()方法. 您可以同时尝试. Dragula为您提供了被删除的div,源div,目标div的ID.

Dragula has three Elements One is Source Div, Target Div and Its associated Element. Following Method Works For Me as Charm except i am Not using get() method which has version issue. You Can Try Both. Dragula gives you the id of dropped div, Source Div, Target Div.

   const dragula = Dragula(['', '']);
      dragula.on('drop', (el, target, source, sibling) => {
        const elementId = $(el).attr("id");
        const targetID = $(target).attr("id");
        const sourceId = $(source).attr("id");
}

这篇关于使用dragula javascript获取已删除div的ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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