jquery's event.stopImmediatePropagation() doesn't seem to be working
I'm working with some existing javascript code which takes an L开发者_如何学CI and makes it droppable to an input field. I wanted to add an additional constraint to this, and enforce this by making my own event handler, and calling event.stopImmediatePropagation() if the constraint is not met. This existing javascript is look like this:
$input.droppable({
accept: accept,
activeClass: 'droppable_active',
hoverClass: 'droppable_hover',
// tolerance: 'touch',
drop: function(e, ui)
{
// do some stuff;
}
And is initiated in my code via the following call:
$('form').dmFrontForm();
Which is a custom jQuery UI which sets that event handler.
Before I make this call, I setup my own handler:
$('input').('drop', function(e, ui) {
if (constraintIsNotMet) {
e.stopImmediatePropagation();
}
});
I verified the order that the event handlers were being called by adding in alert statements (actually no matter what order I put these lines of code, my handler always responded first which is a bit fishy to me), but no matter how hard I try, I can't get the first handler to quit.
I know this is not a direct answer to your question of why it does not stop the propagation, but why not use the built-in accept method ?
http://docs.jquery.com/UI/Droppable#option-accept
example of usage
$('.selector').droppable('option', 'accept', function(){...});
the function should return false to cancel the drop ..
精彩评论