Cœuralooficha提出了一个问题:Attaching hashtag to URL with javascript,或许与您遇到的问题类似。
回答者CMS给出了该问题的处理方式:
You can change the location.hash
property, it will change the current anchor identifier without navigating away form the page, for example you could:
<a href="http://mysite.com/cats" id="cats" class="ajaxLink">Cats</a> <a href="http://mysite.com/dogs" id="dogs" class="ajaxLink">Dogs</a>
Then:
$('.ajaxLink').click(function (e) { location.hash = this.id; // get the clicked link id e.preventDefault(); // cancel navigation // get content with Ajax... });
希望本文对你有帮助,欢迎支持JavaScript中文网
来源:JavaScript中文网 ,转载请注明来源 https://www.javascriptcn.com/post/28561