admin管理员组文章数量:1401438
I have this inline JS call to a function inside an anchor tag and when click it fires the JS function however I don't want the page to jump to the top when I click it.
<a href="#" title="link" onclick="javascript:runMe()">Click Here</a>
And I have this inside the function:
function runMe() {
// do something
return false;
}
I thought the return false would be the correct way to prevent it to jump to the top but it doesn't work?
I have this inline JS call to a function inside an anchor tag and when click it fires the JS function however I don't want the page to jump to the top when I click it.
<a href="#" title="link" onclick="javascript:runMe()">Click Here</a>
And I have this inside the function:
function runMe() {
// do something
return false;
}
I thought the return false would be the correct way to prevent it to jump to the top but it doesn't work?
Share Improve this question asked Aug 27, 2011 at 2:17 user381800user3818001 Answer
Reset to default 8You're not returning the return of the function. :P Basically you are only returning false to the runMe function call but not the element's onclick function call.
do
<a href="#" title="link" onclick="runMe(); return false;">Click Here</a>
or
<a href="#" title="link" onclick="return runMe();">Click Here</a>
本文标签: javascriptPrevent page from jumping to the top onclick JSStack Overflow
版权声明:本文标题:javascript - Prevent page from jumping to the top onclick JS - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744226027a2596092.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论