2015-12-02 83 views
0

我在wordpress主题中使用wordpress visual composer选项卡,我也在wordpress主菜单中使用与#mylink之类的标记相同的选项卡菜单。当我点击菜单中的锚定标记时,我会给出页面重新加载选项。但在页面重新加载之前,它正在向下滚动以查找与该标签内容相关的内容。 这里是我使用如何在javascript或jquery中删除锚定标记散列点击滚动

$('.sub-menu .menu-item a').click(function(e) { 
    location = this.href; 
     location.reload(true); 

    }); 

我想删除当你点击的散列锚标签滚动的代码。

参考网址:http://wtastudios.com/novus2/projectsservices/#solar_Rooftops

+1

你试过'e.preventDefault(); '? – om1

+0

雅我试过了。 –

+0

只需删除这个脚本,希望它的工作正常,并从菜单中删除#标签。 –

回答

0

试试这个

$(document).on('click','.sub-menu .menu-item a',function(e) { 
if($(this).attr('href')).indexOf('#') > -1){ 
//return false; 
e.preventDefault(); 
} 

}); 

不使用CLIK()了,就比较好,因为它甚至以后的document.ready触发了。

那么你只能定位包含#的href。

+0

if($(this).attr).indexOf('#')> -1){说明Uncaught SyntaxError:意外的标记。 –

+0

你需要吸引href参数:'if($(this).attr('href')。indexOf('#')> -1){}' – om1

+0

ya我已经添加了。请查看http://wtastudios.com/novus2/projectsservices/#solar_Rooftops –