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>
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744226028a4564008.html
评论列表(0条)