1

I have code like this:

<a href="#div-part" title="title">go to div part<a>
<form>
...
</form>
<div id="div-part">
<div>

After clicking the anchor tag scroll automatically moves to div part but instead of #div-part in url it adds #undefined in URL. e.g. localhost:80/index.jsp#undefined.

Please help me on this.

4

1 回答 1

-1

这是滚动到特定 div 的解决方案

$(function() {
    $('a').bind('click',function(event){
        var $anchor = $(this);
        $('html, body').stop().animate({
            scrollTop: $($anchor.attr('href')).offset().top
        }, 1000);       

    });
 });

在此处查看演示

于 2014-07-06T07:09:49.753 回答