2017-11-11 139 views
-2

我有兩個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做到這一點?

回答

1

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文件或