获取组件的Drop Target

时间:2011-04-13 06:46:39

标签: javascript jquery

嗨,我想在Drop Event之后获得Drop目标className / ID。有人告诉我怎么弄?

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

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

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

所有DIV组件都必须是可拖动的&amp;可以互相放弃

2 个答案:

答案 0 :(得分:1)

在drop handler

中使用this.id.

jsFiddle demo

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

答案 1 :(得分:0)

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);
        }

    });