【发布时间】:2019-03-23 22:32:33
【问题描述】:
我正在使用 bootstrap 4 并且有一个下拉菜单,并且我有一个用于 scrollspy 和 scrollto 的脚本。当我单击启动下拉菜单时,控制台显示以下错误:
jquery.min.js:2 Uncaught Error: Syntax error, unrecognized expression: http://example.com
at Function.ga.error (jquery.min.js:2)
at ga.tokenize (jquery.min.js:2)
at ga.select (jquery.min.js:2)
at Function.ga [as find] (jquery.min.js:2)
at r.fn.init.find (jquery.min.js:2)
at new r.fn.init (jquery.min.js:2)
at r (jquery.min.js:2)
at HTMLAnchorElement.<anonymous> (scripts.js:27)
at HTMLAnchorElement.dispatch (jquery.min.js:3)
at HTMLAnchorElement.q.handle (jquery.min.js:3)
这是 scripts.js 的内容:
$(document).ready(function() {
$(".nav-link,.dropdown-item").click(function() {
var t = $(this).attr("href");
$('.active').not('.carousel-item.active').removeClass('active');
$("html, body").animate({
scrollTop: $(t).offset().top - 50
}, {
duration: 1e3,
});
$('body').scrollspy({ target: '#navbar-example',offset: $(t).offset().top });
$(this).parent().addClass('active');
return false;
});
});
在控制台调用的第 27 行是:
scrollTop: $(t).offset().top - 50
它有问题的锚点是用于下拉列表中顶级项目的 href - 这是 html:
<a class="nav-link dropdown-toggle" href="http://example.com" id="dropdown01" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Compute</a>
我错过了什么?
提前感谢您的指导。
【问题讨论】:
标签: jquery drop-down-menu bootstrap-4 scrollto scrollspy