【发布时间】:2016-05-18 19:43:24
【问题描述】:
也许我的要求太简单了,也许不是。无论如何,当链接被按下时,我需要调用页面的某个锚点,它会输入一个特定的 URL,并带有一个特定的锚点向下滚动到该锚点。
我是这样用 jquery 做的:
$(document).ready(function() {
var anchor = window.location.hash.substring(1);
if(anchor!="") {
var newAnchor= "'#anchor-" +anchor+"'";
$(newAnchor).trigger("click");
}
});
我认为这是不可能的,我当然没见过,我得到以下错误:
Uncaught Error: Syntax error, unrecognized expression: '#anchor-2015'
是否可以像这样动态调用选择器?还有其他方法吗?
谢谢。
【问题讨论】:
-
window.location.hash = "anchor-" +ancla;
标签: javascript jquery hash anchor