如何在window.location之后添加jquery动作

时间:2014-03-14 05:01:20

标签: 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之后添加操作?

1 个答案:

答案 0 :(得分: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);
});