i try to delete a div
$(".global_class").live('mousedown', function(e)
{
if( (e.which == 3) )
{
// $('#'+this.id+'').remove();
del_function(this.id);
}
e.preventDefault();
}).live('contextmenu', function(e){ e.preventDefault(); });
This code works but the problem is the $('#'+this.id+'').remove();
$(".global_class").live('mousedown', function(e)
didn't start (result -> the context menu will not be blocked).
Hope someone can help me.
Thanks in advance! Pet开发者_StackOverflow社区erWhen you remove the elements that are involved in an event, results in terms of bubbling and defaults and such get a bit squirrelly (even without jQuery's live
being involved). You could do this:
$(".global_class").live('mousedown', function(e)
{
var id = this.id;
if( (e.which == 3) )
{
setTimeout(function() {
del_function(id);
}, 0);
}
e.preventDefault();
}).live('contextmenu', function(e){ e.preventDefault(); });
...so that you remove the div
immediately after the event finishes, rather than during the event.
Off-topic, but you can't cancel the contextmenu
event on all browsers (Opera comes to mind), which you may want to factor into your UI decisions...
精彩评论