How to continue event propagation after cancelling?

前端 未结 8 738
孤街浪徒
孤街浪徒 2020-12-13 11:41

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:

8条回答
  •  情书的邮戳
    2020-12-13 12:23

    We have a similar requirement in our project and this works for me. Tested in chrome and IE11.

    $('a.my-link').click(function(e) {
      e.preventDefault(); 
      if (do_something === true) {
        e.stopPropogation();
        MyApp.confirm("Are you sure you want to navigate away?")
        .done(function() {
          do_something = false;
          // this allows user to navigate 
          $(e.target).click();
        })
      }
    
    })
    

提交回复
热议问题