jquery draggable停止事件 [英] jquery draggable stop event

查看:401
本文介绍了jquery draggable停止事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经搜索了很多。但是我找不到答案。也许是dublicate.Here是我的一些代码:

  $(。box)。draggable({
revert:invalid,
stop:function(ev,ui){
// if(dropped)alert(ui) .item.attr(id);
// else alert(不丢弃);
}
});
$(。box)。droppable ({
accept:function(drag){
return $(drag).attr(data-id)=== $(this).attr(data-id);
},
drop:function(ev,ui){

}
});

我看过可放置的选项可拖动的选项。但它没有帮助。换句话说,如何访问使用可拖动选项,事件和方法删除元素。
同时使用 jQuery Droppable,删除元素



如何获取被删除的元素ID如果从Draggable停止功能中删除它。

解决方案

很容易在中获取一个 。但是不能用 draggable draggable ...

我在以前的项目中试过它,就像魅力一样。



试试这个:

  $(#dragable)。draggable(
{handle:p,
stop:function(event,ui){
console.log(event);
console.log($(ui.helper [0])。children()。attr('id'));
}
});

http://jsfiddle.net/rahulrulez/gg4z10v4/


I have searched a lot of.But I can't find answer.Maybe dublicate.Here is a bit of my code:

$(".box").draggable({
        revert:"invalid",
        stop:function(ev,ui){
            //if(dropped) alert(ui.item.attr("id");
            //else alert("Not dropped");
        }
    });
$(".box").droppable({
        accept:function(drag){
            return $(drag).attr("data-id")===$(this).attr("data-id");
        },
        drop:function(ev,ui){

        }
    });

I have looked droppable options and draggable options.But it isn't helpfull.In other word how to access dropped element using draggable options,events and methods. Also dublicate with jQuery Droppable, get the element dropped

How to get the dropped element Id if it is dropped from Draggable stop function.

解决方案

It's easy to get one in droppable. But not with draggable there's hacky way to get id of dropped element on stop event in draggable...

I tried it in my previous projects, works like charm.

Try this :

$( "#draggable" ).draggable(
      { handle: "p",
        stop: function(event, ui){
          console.log(event);
          console.log($(ui.helper[0]).children().attr('id'));
     }
});

http://jsfiddle.net/rahulrulez/gg4z10v4/

这篇关于jquery draggable停止事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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