取消后如何继续事件传播? [英] How to continue event propagation after cancelling?

查看:83
本文介绍了取消后如何继续事件传播?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用户点击某个链接时,我想向他们呈现一个确认对话框。如果他们点击是,我想继续原来的导航。一个catch:我的确认对话框是通过返回一个jQuery.Deferred对象来实现的,该对象只有当/如果用户点击Yes按钮才解决。所以基本上确认对话框是异步的。

When a user clicks a certain link I would like to present them with a confirmation dialog. If they click "Yes" I would like to continue the original navigation. One catch: my confirmation dialog is implemented by returning a jQuery.Deferred object which is resolved only when/if the user clicks the Yes button. So basically the confirmation dialog is asynchronous.

所以基本上我想要这样的东西:

So basically I want something like this:

$('a.my-link').click(function(e) {
  e.preventDefault(); e.stopPropogation();
  MyApp.confirm("Are you sure you want to navigate away?")
    .done(function() {
      //continue propogation of e
    })
})

当然我可以设置一个标志并重新触发点击,但这是凌乱的。这样做的任何自然的方法?

Of course I could set a flag and re-trigger click but that is messy as heck. Any natural way of doing this?

推荐答案

以下是在Chrome 13中实际工作的代码中的位,令我感到惊讶。

Below are the bits from the code that actually worked in Chrome 13, to my surprise.

function handler (evt ) {
    var t = evt.target;
    ...
    setTimeout( function() {
        t.dispatchEvent( evt )
    }, 1000);
    return false;
}

这不是非常跨浏览器,也可能会在将来修复,因为感觉像安全风险,imho。

This is not very cross-browser, and maybe will be fixed in future, because it feels like security risk, imho.

如果您取消事件传播,我不知道会发生什么。

And i don't know what happens, if you cancel event propagation.

这篇关于取消后如何继续事件传播?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆