简体   繁体   English

单击按钮并更改页面后,滚动回到首页

[英]Scroll back to top page when button clicked and page changed

I'm having a multi-step form with a multi-step progress bar above. 我有一个多步骤表单,上面有一个多步进度栏。 For the multi-step form I'm using tab-panes with "step1/2/3/4" as id's. 对于多步骤表单,我使用带有“ step1 / 2/3/4”作为id的选项卡窗格。 When I'm at the first section and I scroll down, I want to click the "Next Section" button. 当我在第一部分中并向下滚动时,我想单击“下一部分”按钮。 After the button is clicked, it takes me to the next section but at the same point I was when I scrolled down to click the button. 单击按钮后,它将带我到下一部分,但与向下滚动以单击按钮时相同。 What I want to do is to take me to the top of the page when the section is changed by clicking the button. 我想做的就是通过单击按钮将我更改为页面顶部。 I tried to add this method into my javascript code but it doesn't work: 我试图将此方法添加到我的javascript代码中,但是它不起作用:

$(document).ready(function(){
    $(this).scrollTop(0);
});

Any help would be appreciated! 任何帮助,将不胜感激! Thanks! 谢谢!

Here is my JS code: 这是我的JS代码:

$(document).ready(function () {
  //Initialize tooltips
  $('.nav-tabs > li a[title]').tooltip();

  // METHOD FOR THE PROGRESS BAR 
  $('a[data-toggle="tab"]').on('show.bs.tab', function (e) {

    var $target = $(e.target);

    if ($target.parent().hasClass('disabled')) {
      return false;
    }
  });

  // NEXT STEP METHOD - WHEN BUTTON CLICKED TAKES TO THE NEXT SECTION
  $(".next-step").click(function (e) {

    var $active = $('.progressbar .nav-tabs li.active');
    $active.next().removeClass('disabled');
    nextTab($active);

  });


  // PREVIOUS STEP METHOD - WHEN BUTTON CLICKED TAKES TO THE PREVIOUS SECTION
  $(".prev-step").click(function (e) {

    var $active = $('.progressbar .nav-tabs li.active');
    prevTab($active);

  });
});

And this is the button from the bottom of the tab-pane: 这是选项卡窗格底部的按钮:

<button type="button" name="next" class="next proceed-to-payment next-step" value="Proceed to Payment">Proceed to Payment</button>
 <button type="button" name="previous" class="previous back-to-cart prev-step" value="Back" id="back-to-cart-id">Back</button>

Add $(document).scrollTop(0) or window.scrollTo(0, 0); 添加$(document).scrollTop(0)window.scrollTo(0, 0); to the $(".next-step").click and $(".prev-step").click functions $(".next-step").click$(".prev-step").click函数

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM