开发者

Prevent page from jumping to the top onclick JS

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?


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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜