javascript - Prevent page from jumping to the top onclick JS - Stack Overflow

I have this inline JS call to a function inside an anchor tag and when click it fires the JS function h

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 user381800user381800
Add a ment  | 

1 Answer 1

Reset to default 8

You'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>

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744226028a4564008.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信