HTML
CSS
JavaScript
HTML
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
<title>表单向导 - 光年(Light Year Admin)后台管理系统模板</title>
<link rel="icon" href="favicon.ico" type="image/ico">
<meta name="keywords" content="LightYear,光年,后台模板,后台管理系统,光年HTML模板">
<meta name="description" content="LightYear是一个基于Bootstrap v3.3.7的后台管理系统的HTML模板。">
<meta name="author" content="yinqi">
<link href="http://lyear.itshubao.com/iframe/css/bootstrap.min.css" rel="stylesheet">
<link href="http://example.itshubao.com/demo/css/materialdesignicons.min.css" rel="stylesheet">
<link href="http://lyear.itshubao.com/iframe/css/style.min.css" rel="stylesheet">
</head>
  
<body>
      
      <div class="container-fluid">
        
        <div class="row">
          <div class="col-lg-12">
            <div class="card">
              <div class="card-header"><h4>表单向导</h4></div>
              <div class="card-body">
                
                <form action="lyear_pages_guide.html" method="post" class="guide-box" data-navigateable="true">
                  <ul class="nav-step step-dots">
                    <li class="nav-step-item active">
                      <span>步骤一</span>
                      <a class="active" data-toggle="tab" href="#step-1"></a>
                    </li>

                    <li class="nav-step-item">
                      <span>步骤三</span>
                      <a data-toggle="tab" href="#step-2"></a>
                    </li>

                    <li class="nav-step-item">
                      <span>步骤四</span>
                      <a data-toggle="tab" href="#step-3"></a>
                    </li>

                    <li class="nav-step-item">
                      <span>步骤五</span>
                      <a data-toggle="tab" href="#step-4"></a>
                    </li>
                  </ul>
                  <!--对应内容-->
                  <div class="nav-step-content">
                    <div class="nav-step-pane hidden active" id="step-1" data-provide="validation">
                      <div class="form-group">
                        <label>姓名</label>
                        <input class="form-control" type="text">
                      </div>
                    </div>

                    <div class="nav-step-pane hidden" id="step-2">
                      <div class="form-group">
                        <label>邮箱地址</label>
                        <input class="form-control" type="text">
                      </div>
                    </div>

                    <div class="nav-step-pane hidden" id="step-3">
                      <div class="form-group">
                        <label>设置密码</label>
                        <input class="form-control" type="password">
                      </div>
                    </div>

                    <div class="nav-step-pane hidden" id="step-4">
                      <div class="form-group">
                        <label>备注</label>
                        <input class="form-control" type="text">
                      </div>
                    </div>
                  </div>
                  <!--End 对应内容-->
                  <hr>
                  <div class="nav-step-button">
                    <button class="btn btn-secondary disabled" data-wizard="prev" type="button">上一步</button>
                    <button class="btn btn-secondary" data-wizard="next" type="button">下一步</button>
                    <button class="btn btn-primary hidden" data-wizard="finish" type="button">完成</button>
                  </div>
                </form>
       
              </div>
            </div>
          </div>
          
        </div>
        
      </div>
      

<script type="text/javascript" src="http://lyear.itshubao.com/iframe/js/jquery.min.js"></script>
<script type="text/javascript" src="http://lyear.itshubao.com/iframe/js/bootstrap.min.js"></script>
<script type="text/javascript" src="http://lyear.itshubao.com/iframe/js/perfect-scrollbar.min.js"></script>
<script type="text/javascript" src="http://lyear.itshubao.com/iframe/js/main.min.js"></script>
<!--向导插件-->
<script type="text/javascript" src="http://lyear.itshubao.com/iframe/js/jquery.bootstrap.wizard.min.js"></script>

</body>
</html>
CSS

  
JavaScript
$(document).ready(function() {
    var guideObj = $('.guide-box'); // 表单向导表单
    var nav_item = guideObj.find('.nav-step-item'); // 表单向导步骤
    var tab_pane = guideObj.find('.nav-step-pane'); // 表单向导步骤对应内容
    
    guideObj.bootstrapWizard({
        'tabClass': 'nav-step',
        'nextSelector': '[data-wizard="next"]',
        'previousSelector': '[data-wizard="prev"]',
        'finishSelector': '[data-wizard="finish"]',
        'onTabClick': function(e, t, i) {
            if (!$('.guide-box').is('[data-navigateable="true"]')) return ! 1
        },
        'onTabShow': function(e, t, i) {
            t.children(":gt(" + i + ").complete").removeClass("complete");
            t.children(":lt(" + i + "):not(.complete)").addClass("complete");
        },
        'onNext': function(tab, navigation, index){
            var current_index = guideObj.bootstrapWizard('currentIndex');
            var curr_tab      = tab_pane.eq(current_index);
            
            if (index == 1) {
                // 步骤1
                var input1 = curr_tab.find('input');
                var username = input1.val();
                if (username.length == 0) {
                    input1.parent('.form-group').addClass('has-error');
                    return false;
                } else {
                    input1.parent('.form-group').removeClass('has-error');
                }
                // 也可以在这里增加实时验证机制
            } else if (index == 2) {
                // 步骤2
                var input2 = curr_tab.find('input');
                var email = input2.val();
                if (email.length == 0) {
                    input2.parent('.form-group').addClass('has-error');
                    return false;
                } else {
                    var myreg = /^([\.a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-])+/;
                    if(!myreg.test(email)){
                        input2.parent('.form-group').addClass('has-error');
                        return false;
                    } else {
                        input2.parent('.form-group').removeClass('has-error');
                    }
                }
            } else if (index == 3) {
              // 步骤3
              
            } else if (index == 4) {
              // 步骤4
              
            }
        },
        'onFinish': function(e, t, i) {
            var nav = nav_item.eq(i);
            nav.addClass('complete').removeClass('active');
            // 点击完成后处理提交
            return false;
        }
    });
});