我想使用http://balupton.github.com/jquery-scrollto/demo/自动滚动相关导航链接。使用下面的代码,这是我得到的错误:Uncaught Error: Syntax error, unrecognized expression: #/article/
这显然是由斜杠(这是 ajax 插件中必需的命名空间)引起的,当我删除它们时,错误消失但仍然不起作用:http:// jsbin.com/ifutav/3/edit 但e.preventDefault()
确实如此。所以很明显这里发生了两个错误:
- jQuery 不喜欢这个
href
值 - scrollTo 无法正常工作
HTML:链接
<nav id="nav">
<ul>
<li><a href="#/item-1/">Item 1</a></li>
<li><a href="#/item-2/">Item 2</a></li>
<li><a href="#/item-3/">Item 3</a></li>
<li><a href="#/item-4/">Item 4</a></li>
</ul>
</nav>
HTML:元素
<section id="/item-1/"></section>
<section id="/item-2/"></section>
<section id="/item-3/"></section>
<section id="/item-4/"></section>
Javascript
$('nav ul li a[href^="#"]').each(function() {
// store values so it doesn't have to execute onclick
var $this = $(this),
value = $this.attr('href'),
element = $(value);
$this.click(function(e) {
// prevent default scrolling
e.preventDefault();
// scrollTo element
element.scrollTo();
});
});
我不知道这两个方面背后的原因,但我认为它们是某种类型错误?我...
提前谢谢。