如何在javascript中捕获dragend事件?

Ash*_*hir 6 javascript jquery jquery-ui jquery-ui-draggable

我正试图在Javascript中捕获dragend事件以获得可拖动的DIV.dragend事件根本没有被解雇,为什么?以及如何解决这个问题?PS,我是来自jQuery UI 1.9.2的.draggable()方法

这是我的代码:http://jsfiddle.net/vBMav/

HTML:

<div id="divId"> ... </div>
Run Code Online (Sandbox Code Playgroud)

CSS:

#divId {
    background-color: #000000;
    color: #ffffff;
    height: 200px;
    width: 200px;
}
Run Code Online (Sandbox Code Playgroud)

使用Javascript:

$('#divId').draggable(); 

$('#divId')
    .bind('dragstart', function(){ $("#divId").text("drag start"); })
    .bind('drag',      function(){ $("#divId").text("dragging");   })
    .bind('dragend',   function(){ $("#divId").text("drag ended"); });
Run Code Online (Sandbox Code Playgroud)

Jac*_*cob 13

尝试使用'dragstop'而不是'dragend'

.bind('dragstop',function(){$("#divId").text("drag ended");});

  • 这是文档中所写的正确用法:http://api.jqueryui.com/draggable/ (2认同)