-->

Cancel draggable div on start [closed]

2019-09-19 06:23发布

问题:

What I have:
Draggable divs that have an alert on start and revert when dropped.

What I need:
When user tries to drag the div, an alert pops up saying you can't drag it and the dragging stops before it even goes anywhere.

回答1:

You can return false within the start() method to accomplish this:

$("#draggable").draggable({
    start: function(event, ui) {
        alert('Dragging is disabled');
        return false;
    }
});

JSFiddle: http://jsfiddle.net/Jam8Z/