如何在页面加载中显示页面的顶部div?

问题描述:

我有两个html页面。 page1.htmlpage2.html。我想单击页面1中的href,并且我想要清除page2.html,但是页面顶部的特定div。如何在页面加载中显示页面的顶部div?

第1页

<li><a href="page2.html#profileData">Profile View</a></li>

第2页

<div id="profileData"> </div>

只有单页包含了许多div.I想在页面顶部时page2.html页面打开然后ProfileData格。

如何用jQuery或JavaScript做到这一点?

href="page2.html#profileData",该功能将滚动到元件#profileData

$(function(){ 
    // get hash value profileData 
    var scrolldiv = window.location.hash; 
    // now scroll to element with that id 
    $('html, body').animate({ scrollTop: $(scrolldiv).offset().top }); 
}); 
+0

感谢响应,其中i将此功能??在JavaScript文件? – don

+0

所以它需要进入一个JavaScript文件或