I'm having trouble using the event.preventDefault(); for an ahref on my DOM

后端 未结 4 726
[愿得一人]
[愿得一人] 2021-02-09 13:09

I\'m having trouble using the event.preventDefault(); for an ahref on my DOM.

How do you prevent the url from posting a nofollow delete, as spe

4条回答
  •  暖寄归人
    2021-02-09 13:59

    It is possible that instead of just event.preventDefault(), you need to do return false also or instead. preventDefault() prevents the default action, but the event still bubbles up, possibly to the next handler, which could be the rails handler that Fredrik pointed out:

     $(rails.linkClickSelector).live('click.rails', function(e) {
        var link = $(this);
        if (!rails.allowAction(link)) return rails.stopEverything(e);
    
        if (link.data('remote') !== undefined) {
          rails.handleRemote(link);
          return false;
        } else if (link.data('method')) {
          rails.handleMethod(link);
          return false;
        }
      });
    

提交回复
热议问题