jQuery滚动到不同php页面中的元素

jQuery滚动到不同php页面中的元素,php,jquery,html,scroll,Php,Jquery,Html,Scroll,我在reply.php文件中有一个href标记 <a id="click" href="javascript:replytoQuestion('<?=$comment_id?>')">Answer <?=htmlentities($row['studentname'])?> </a> 然后我在index.php文件中有一个表单 <form id="answerForm" 当用户单击href标签页中的应答时,必须滚动至表单id=answer

我在reply.php文件中有一个href标记

<a id="click" href="javascript:replytoQuestion('<?=$comment_id?>')">Answer <?=htmlentities($row['studentname'])?> </a>
然后我在index.php文件中有一个表单

<form id="answerForm"
当用户单击href标签页中的应答时,必须滚动至表单id=answerForm

我试着用这个:

<script>
    $(document).ready(function (){
        $("#click").click(function (){
            //$(this).animate(function(){
                $('html, body').animate({
                    scrollTop: $("#answer").offset().top
                }, 2000);
            //});
        });
    });
</script>
但它不起作用


任何建议

很高兴它奏效了,我的想法很简单:

function replytoQuestion(numberId, idName) {
     var numberId; // Number id
     // *** Some treatment with numberId *** //
     return go(idName);
}

function go(idName) {
    // *** scroll to the div with smootheffect *** //
}

那么你要离开这个页面吗?如果是的话,请向我们展示replytoQuestion功能,因为这比你滚动离开的页面要有趣得多?@Dev'Hamz Sorry click应该再次出现,在你发布replytoQuestion之前,这一切都是完全无关的function@adeno函数replytoQuestionid{document.getElementById'inReplyTo'.value=id;//可能我可以编写一个代码向下滚动到此处的“注释到答案”框。我不知道如何编写它}您可以在函数replytoQuestion中使用锚,并使用jQuery实现平滑效果。