【发布时间】:2015-02-26 05:49:45
【问题描述】:
我正在使用该代码:
$(function() {
$('a[href*=#]:not([href=#])').click(function() {
if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
var target = $(this.hash);
target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
if (target.length) {
$('html,body').animate({
scrollTop: target.offset().top
}, 1000);
return false;
}
}
});
});
和<a href="#allcontentcontact"> 链接到div <div id="allcontentcontact"></div>。
问题是: “#allcontentcontact”在我的主页上,所以代码只有在我在主页上时才能完美运行。但我有一个固定的菜单链接到其他页面!因此,当我在另一个页面上时,我需要一些东西来使我的 a href 链接到该 div。
谢谢!
【问题讨论】:
-
html代码在哪里?
-
我想我发布了所有重要的信息。你还需要看什么?
标签: javascript jquery html anchor