我为提出错误的问题而道歉。然而,我发现了一篇帖子,正是在问我究竟想要弄清楚什么。我在这里发现了这篇文章:https://stackoverflow.com/questions/20785188/jquery-scrollto-internal-external-page。
使用下面的代码,我想了解如何使用href =" index.php / #home"在内部和外部页面上工作。另一篇文章显示了此示例http://vostrel.cz/so/9652944/page.html,但它不适用于内部网页。
使用Javascript:
(function($) {
var jump=function(e)
{
if (e){e.preventDefault();var target = $(this).attr("href");}
else{var target = location.hash;}
$('html,body').animate({scrollTop: $(target).offset().top},1100,function(){location.hash = target;});
}
$('html, body').hide();
$(document).ready(function()
{
$('a[href^=#]').bind("click", jump);
if (location.hash){
setTimeout(function(){$('html, body').scrollTop(0).show();jump()},0);
}
else{$('html, body').show()}
});
})(jQuery)
答案 0 :(得分:0)
$('a[href="index.php#home"]').on("click", jump);
如果它位于您网站的根目录,您可以这样:
$('a[href="/#home"]').on("click", jump);
答案 1 :(得分:0)
$('a[href^=#], a[href^="index.php#"]').bind("click", jump);
这将是一个简单的解决方案,如果你想匹配任何页面中的哈希或者有其他限制,我会更新答案。
答案 2 :(得分:0)
我相信你想要jQuery Attribute ends with selector
$('a[href$="index.php#home"]').bind("click", jump);