Stay on a current tab after after submitting a form using jQuery

后端 未结 8 600
一生所求
一生所求 2021-01-18 08:14

I\'m trying to stay on a specif tab ( in this case tab2 ) but after clicking the submit button the tab reverts to tab 1 which has the default class of active. I have hit a b

8条回答
  •  迷失自我
    2021-01-18 08:42

    Use JQuery.ajax() in your Submit button's onclick() event to post-back values asynchronously. That way, there won't be a window reload, as the postback will occur in the background.

    HTML

    JavaScript

    ​function submit(){
       $.ajax({
      type: "POST",
      url: "submit.php",
      data: { param1: "param1", param2: "param2" }
      }).done(function() {
          alert( "Submitted" );
      });
      }​
    

提交回复
热议问题