1
我在写一个ajax导航脚本。 我发现我可以通过使用jquery没有方法错误
('a[href=' + document.location.hash + ']').addClass('current');
凸显当前部分进入菜单,但我得到这个错误:
Object a[href="#home"] has no method 'addClass'
什么建议吗?
我在写一个ajax导航脚本。 我发现我可以通过使用jquery没有方法错误
('a[href=' + document.location.hash + ']').addClass('current');
凸显当前部分进入菜单,但我得到这个错误:
Object a[href="#home"] has no method 'addClass'
什么建议吗?
东西的缺失:
$('a[href="' + document.location.hash + '"]').addClass('current');
你忘了$
标志?
尝试:
$('a[href=' + document.location.hash + ']').addClass('current');
没有$
,JavaScript的解析器会认为这是一个字符串对象。
感谢它工作正常;将javascript,php和html标记混合到一行代码中会令人疯狂地混淆。 – g0dl3ss 2012-04-04 09:51:40