jQuery Draggable类查找

时间:2017-01-31 06:15:17

标签: jquery html css3 jquery-ui

我在html标签中有三个类。我给了一个班级的拖延。我怎么知道班级价值。

<div class="drag dgtf hgyh">
  //content 
</div>

<div class="drop">
  //content 
</div>

Jquery如下

$('.drag').draggable({
  drag:function(){}
})

$('.drop').draggable({
  drop:function(event, ui){
    // here i need to get particular class which has drag
    // that is how can i get 'drag' class name
  }
})

2 个答案:

答案 0 :(得分:1)

尝试:

drop:function(event, ui){
 ui.draggable.attr("id") // For ID
 ui.draggable.attr("class") // For Class
}

更新:

 ui.draggable.attr("class").split(' ')[0] // May be 1 or 2

答案 1 :(得分:0)

获取已删除元素的类。

$('.drop').draggable({
  drop:function(event, ui){
      var draggable_class = ui.draggable[0].attr("class");
  }
})