使用 jQuery Mobile,尝试获取外部哈希链接以打开静态页面(工作),触发打开给定的手风琴(工作),并滚动到该部分(失败)。以下脚本引发了未定义的错误,但我找不到问题。谁能告诉我为什么这里没有定义“链接”?或者是其他未定义的东西?或者我只是有一个愚蠢的错字?
$(window).load(function(){
var hash = window.location.hash;
var anchor = hash.substring(hash.lastIndexOf('#') + 1, hash.length);
var link = 'a#' + anchor;
if(window.location.hash){
$('.pages').find(link).trigger('expand'); /* this works fine, accordion opens */
console.log(link); /* this also works fine, logs correct string */
$('html, body').animate({
scrollTop: $(link).offset().top /* this triggers 'cannot read property "top" of undefined', scroll fails and function falls apart */
}, 1000);
}
});