简体   繁体   English

在锚标记之前执行功能,并在之后加载

[英]Execute function before anchor tag and load it after

How can i execute a function before I click on anchor tag <a href="/foo" id="foo">Foo</a> and after click on it ? 在单击锚标记<a href="/foo" id="foo">Foo</a>和单击后如何执行函数?

I try this : 我尝试这样:

$(document).on('click', '#foo', function(e) {
      // stuff to do
      return false;
}

The function is executed but the link /foo is not loading like the default behavior. 该函数已执行,但是/ foo链接没有像默认行为那样加载。

Well, I don't understand why people shout at you, being clearer, your question can be answered this way: 好吧,我不明白为什么人们会对你大喊大叫,更清楚地说,你的问题可以这样回答:

$(document).on('click', '#foo', function(e) {
  // stuff to do
  alert("Hello");
  // finally follow the link
  location.href = $(this).attr("href");
  // Or may be giving `return true;` could work?
  return false;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM