正如标题所说,我正在获取位置哈希并将其存储在var中。然后我搜索一个带有name属性的链接,该属性与哈希匹配并为其添加一个类。
我目前使用的代码是:
var hash = window.location.hash.substring(1);
$('a[name*='+hash+']').addClass("boo");
虽然没有运气?任何建议都将不胜感激。
答案 0 :(得分:1)
你的代码很好,只需删除星号(*)并添加引用哈希:
var hash = window.location.hash.substring(1);
$('a[name="'+hash+'"]').addClass("boo");