我想弄明白为什么在IE7中我不能顺畅地向上滚动到页面的顶部。所以我注释掉了我的主代码,只是想看看带偏移量的target的值是多少。如果我将以下代码放入IE7...
function scrollbackup() {
//setup anchor links for each panel
//create the links for each section
var link = '<a class="top" href="#mapSVG">[back to top]</a>';
$('#mMap a').each(function () {
$(this).nextUntil('a', 'p').last().after(link);
});
//on click, smooth scrolling back to top
$('a[href*=#]').bind('click', function (e) {
e.preventDefault();
var target = $(this).attr("href");
var elementTop = $(target).offset().top;
console.log(elementTop);
/*
$('html, body').stop().animate({ scrollTop: $(target).offset().top }, 1000, function() {
location.hash = target;
});
*/
});
}我在IE7中得到以下错误...
SCRIPT5022: Syntax error, unrecognized expression: http://.../index2.html#mapSVG
jquery-1.8.3.min.js, line 2 character 59313错误发生在我单击元素之后,我不知道它为什么会出现在那里……
感谢您的意见
发布于 2013-04-27 00:59:31
这个错误是jQuery在抱怨一个糟糕的选择器。我的猜测是,在您的<a>标记中,您使用的是http://example.com/index2.html#mapSVG,而不仅仅是#mapSVG。
所以当你做$(target)时,你传递的是整个URL,这就破坏了jQuery。
要解决此问题,请改用var target = $(this).prop("hash");。
https://stackoverflow.com/questions/16241258
复制相似问题