2014-03-14 24 views
0

添加一個jQuery的動作有這樣的代碼:我之後怎麼window.location的

jQuery('li.exhibitor-inquery a').click(function(event) { 
    window.location = '/#inquiry-trigger'; 
    event.preventDefault(); 

    jQuery('html, body').animate({ 
     scrollTop: jQuery('#inquiry-trigger').offset().top 
     }, 500); 

    jQuery('.textwidget .wpcf7').slideToggle('slow'); 
    jQuery('#inquiry-trigger i').toggleClass('glyphicon-chevron-down glyphicon-chevron-up', 200); 
}); 

現在如果li.exhibitor-inquery a點擊,同時在主頁上,它滾動的形式和開放的形式了。但是如果在另一個頁面上,這隻能進入主頁並跳轉,它不會滾動到或打開它。

那麼如何在window.location之後添加動作?

回答

0

試試這個:

jQuery('li.exhibitor-inquery a').click(function(event) { 
    window.location.href = 'http://'+window.host+'#inquiry-trigger'; 
// I assume #inquiry-trigger is on home page, you can set the page in third string otherwise. 
    event.preventDefault(); 

    jQuery('html, body').animate({ 
     scrollTop: jQuery('#inquiry-trigger').offset().top 
     }, 500); 

    jQuery('.textwidget .wpcf7').slideToggle('slow'); 
    jQuery('#inquiry-trigger i').toggleClass('glyphicon-chevron-down glyphicon-chevron-up', 200); 
}); 
+0

謝謝,但沒有好,只是做同樣的事情上面的代碼,如果我把這個網站的網址在+ window.host +,如果我離開了+ window.host +它打開到一個未定義的頁面。 – atomicadam

+0

@ user1936794你能分享一個相同的小提琴嗎? –

相關問題