Anchor click and keeping page position?

In my page there are some anchor that has no link, like this:

<a href="#">Anchor</a>

When I click anchor that is bottom of the page, Page is scrolling to top. I want to keep page position, if I clicked the link. How Can I do this. (no js is better for me)

I hope, I could explain.

Thanks in advance.


You'll still have to use JS, but you can do it inline:

<a href="javascript:void(0);">Test</a>​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​

Demo: http://jsfiddle.net/7ppZT/

Alternatively, you can capture the event:

$('a[href^="#"]').click(function(e) {
    e.preventDefault();
});

You can put anchors in anywhere in the page where you want it to go.

<a href="#stophere">Anchor</a>

<a id='stophere'>Bottom Of Page</a>

Then, the link will go to the named anchor. Just stick in that element wherever you want to stop.


为了解决这个问题,我使用这个代码, 它是脚本解决方案,但适用于所有浏览器

<a href="javascript:void(0)">Anchor</a>
链接地址: http://www.djcxy.com/p/88980.html

上一篇: 有没有任何方法来书签或链接到一个页面的一部分没有锚点?

下一篇: 锚点击并保持页面位置?