最佳答案
我想编写一个锚标记,它执行一些 JavaScript,然后继续前进到 href
带它去的地方。调用一个执行我的 JavaScript 并将 window.location
或 top.location
设置为 href
位置的函数对我来说不起作用。
因此,假设我在页面上有一个 id 为“ Foo”的元素,我想创建一个类似于下面这样的锚:
<a href="#Foo" onclick="runMyFunction(); return false;">Do it!</a>
当单击这个命令时,我想执行 runMyfunction,然后将页面跳转到 #Foo
(不会导致重新加载——使用 top.location
会导致重新加载页面)。
建议? 我很乐意使用 jQuery,如果它可以帮助这里..。