2015-12-02 24 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 –