【发布时间】:2015-01-20 09:40:16
【问题描述】:
我正在更新一个使用 jquery-1.4.3.min.js 的旧项目。这干扰了我正在研究的一些新东西,所以我不得不用最新版本替换它,现在我得到了 Uncaught TypeError: Cannot read property 'substr' of undefined。
研究这个已经有一段时间了,我很难过。非常感谢任何帮助!
它的来源
$link = $('a[hash=#' + $inview + ']').parent().attr('id').substr(4);
如果需要,这里是全部内容
$(window).scroll(function() {
$inview = $('section:in-viewport header').parent().attr('id');
if ($('a[hash=#' + $inview + ']') !== null) {
$link = $('a[hash=#' + $inview + ']').parent().attr('id').substr(4);
}
if ($link != $nCurrentActive && scrolling == 1) {
$nav.removeClass('active');
offMenu($nCurrentActive);
$nCurrentActive = $link;
$('#nav-'+$nCurrentActive).addClass('active');
onScrollMenu($nCurrentActive);
}
});
【问题讨论】:
-
嗨@stanced,你能提供一些HTML吗?
-
您可能希望正确转义属性选择器...如果您的 ID 包含未转义的
'、"或[space]字符,这些字符将导致属性选择器无效。
标签: javascript jquery