右键单击删除 div(块上下文菜单)
我的右键单击上下文菜单有问题
,我尝试删除一个 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.id+'').remove();
< br>
jquery 删除了 div 并且实时 $(".global_class").live('mousedown', function(e)
没有启动(结果 -> 上下文菜单不会被阻止)。
希望有人可以帮助我。
预先感谢!
彼得
i have a problem with the right-click-contextmenu
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();
jquery removes the div and the live $(".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!
Peter
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您删除事件中涉及的元素时,会导致冒泡和默认值,从而变得有点奇怪(即使不涉及 jQuery 的
live
)。您可以这样做:...以便您在事件结束后立即删除
div
,而不是在事件期间。离题了,但您无法取消所有浏览器上的
contextmenu
事件(我想到的是 Opera),您可能需要将其纳入您的 UI 决策中...When 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:...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...