开发者

get Drop Target of component

开发者 https://www.devze.com 2023-02-25 17:54 出处:网络
Hi, I want to get Drop target className/ID after Drop Event. Does anybody tell me how to get ? <div class=\"drop_1\" id=\"drop1\"></div>

Hi, I want to get Drop target className/ID after Drop Event. Does anybody tell me how to get ?

<div class="drop_1" id="drop1"></div>

<div class="drop_2" id="drop2"></div>

<div class="drop_3" id="drop3"></div>

all DIV component must be drag-able & drop-ab开发者_开发百科le onto each other


use the this.id inside the drop handler

jsFiddle demo

$( ".selector" ).droppable({
   drop: function(event, ui) {
       console.log(this.id);
   }
});


Example

$(function() {

      ***/* Make draggable */***

        $(".drop_1, .drop_2, .drop_3").draggable();

        var dropOpts = {
        accept:".drop_1, .drop_2, .drop_3",
        drop:dropCallback,
        greedy:true
          };

    /* Droppable */

    $(".drop_1, .drop_2, .drop_3").droppable(dropOpts);

    /*get your Drop target*/

     function dropCallback(e) {
        alert("The firing droppable was " + e.target.className);
        }

    });
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号