最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Using Jquery to drag and drop, get value from dropped div - Stack Overflow

programmeradmin4浏览0评论

I am using Jquery to making drag and drop.

My short javascript to make an item to drag is:

$(".draggable").draggable();

My short javascript to make a dropable area is:

$("#droppable").droppable();

Here is my dragable item short HTML code:

 <div id="Item[]" class="puterItem draggable">
    <img src="img/.png" class="assetImg" alt="Computer Info" title="">
    <span id="owner[]" class="textLabel"></span>
    <span id="ipaddress[]" class="textLabel"></span>
 </div>

Does someone know how to get the values from dropped items in dropable area? I want to create the object array form the dropped items?

Thank you so much.

I am using Jquery to making drag and drop.

My short javascript to make an item to drag is:

$(".draggable").draggable();

My short javascript to make a dropable area is:

$("#droppable").droppable();

Here is my dragable item short HTML code:

 <div id="Item[]" class="puterItem draggable">
    <img src="img/.png" class="assetImg" alt="Computer Info" title="">
    <span id="owner[]" class="textLabel"></span>
    <span id="ipaddress[]" class="textLabel"></span>
 </div>

Does someone know how to get the values from dropped items in dropable area? I want to create the object array form the dropped items?

Thank you so much.

Share Improve this question asked Dec 3, 2014 at 4:07 SalapaosaikaiSalapaosaikai 211 silver badge3 bronze badges 3
  • are you using a library like jQuery ui? – Shiala Commented Dec 3, 2014 at 4:14
  • Im using jquery & jquery-ui. – Salapaosaikai Commented Dec 3, 2014 at 4:17
  • cerlin beat me to it, his answer should do – Shiala Commented Dec 3, 2014 at 4:20
Add a ment  | 

2 Answers 2

Reset to default 5

You can use the ui.draggable object in drop action

$( "#droppable" ).droppable({
    drop: function( event, ui ) {
        $(this).append($(ui.draggable).find('img'));
    }
})

Here ui.draggable is the element which you have dropped. (in this case the whole div)

You must use the drop event for droppable. Here is what I mean.

var items;
$( "#draggable" ).draggable();
$( "#droppable" ).droppable({
    drop: function(event,ui) {
        items = [ui.draggable];
    }
});

Here is a working fiddle http://jsfiddle/wLkutytx/

Source: http://api.jqueryui./droppable/#event-drop

发布评论

评论列表(0)

  1. 暂无评论