jquery - how could prevent clicked link when I move links with drag&drop?
I allow move (drag&drop) some elements which contains inside link (a
), After user drop it, it redirects browser to href
of moved element. How could I allow t开发者_C百科o click that element and drag&drop its also?
I use http://dragsort.codeplex.com/ plugin.
You'd prevent the default behaviour from being actioned on links, buttons and the like by using preventDefault()
;
$( ".selector" ).draggable({
stop: function(event, ui) {
// Do some stuff when you've finished dragging your element
event.preventDefault(); }
});
Check the jQuery API for more information.
You need to do call event.preventDefault() when you want the default action to be skipped. It's up to you to figure out if the item was being dragged and so should not be navigated, -vs- a standard click. But assuming you store a flag in data, it might look something like this:
$('.something').click(function(event) {
if ($(this).data('dragging')) {
event.preventDefault();
$(this).data('dragging',false);
}
}
精彩评论