所以,你想改變的默認行爲:
<a href="#">click</a>
所以它,而不是把你帶到你的「主」分區:<div class="main">content</div>
你可以做什麼用JavaScript和jQuery是寫功能標識與HREF =「#」網頁上的錨定體,並告訴他們執行你想要的行爲,而不是默認的,就像這樣:
// select a elements with href="#" and add event listener on click
$('a[href="#"]').on('click', function(e){
// prevent default behaviour of jumping to the top of the page
e.preventDefault();
// get target element position in pixels
target = $($('div.main')).position().top;
// animate a scroll effect to the pixel location
$('html,body').stop().animate({ scrollTop: target });
});
問題是問如何''#的意義從「頁面頂部的」更改爲「符合ID#A股利」。它沒有要求如何在#後鍵入id。 – Quentin
謝謝@Quentin你真正理解我的問題.....我想改變一個href =「#」>的默認位置點擊指向帶有「main」類的div元素 – ebukaloper
是的,謝謝!希望這是更有幫助:) – Frish