开门见山,直接讲使用。
实作效果:
首先自然是引入jquery.smartWizard-2.0.js,
然后html元素这样写:
- <!-- 提交故障配置的form -->
- <form id="saveFiConfigs" action="addFiConfigs.action?fiBean.appProfile.id=${fiBean.appProfile.id}" method="post">
- <!-- Tabs -->
- <div id="wizard" class="swMain">
- <ul>
- <li>
- <a href="#step-1">
- <label class="stepNumber">1</label>
- <span class="stepDesc">
- 注入对象<br />
- <small>选择故障注入对象</small>
- </span>
- </a>
- </li>
- <li>
- <a href="#step-2">
- <label class="stepNumber">2</label>
- <span class="stepDesc">
- 故障类型和故障参数<br />
- <small>选择故障类型和配置故障参数</small>
- </span>
- </a>
- </li>
- <li>
- <a href="#step-3">
- <label class="stepNumber">3</label>
- <span class="stepDesc">
- 确认提交<br />
- <small>确认配置并提交保存</small>
- </span>
- </a>
- </li>
- </ul>
- <div id="step-1">
- <h2 class="StepTitle">Step 1: 选择故障注入对象</h2>
- // 这里写向导框中的内容,可以是table或者div等等
- ...
- </div>
- <div id="step-2">
- <h2 class="StepTitle">Step 2: 故障类型和故障参数</h2>
- <br/>
- ...
- </div>
- <div id="step-3">
- <h2 class="StepTitle">Step 3: 确认配置并提交保存</h2>
- ...
- </div>
- </div>
- <!-- End SmartWizard Content -->
- </form>
一般向导都是一次性提交,所以,外面一般会用form包裹起来。
javascript代码:
- // Smart Wizard
- jQuery(document).ready(function(){
- jQuery('#wizard').smartWizard({transitionEffect:'slideleft',onLeaveStep:leaveAStepCallback,onFinish:onFinishCallback,enableFinishButton:true});
- function leaveAStepCallback(obj){
- var step_num= obj.attr('rel');
- return validateSteps(step_num);
- }
- function onFinishCallback(){
- if(validateAllSteps()){
- jQuery('form').submit();
- }
- }
- });
- function validateAllSteps(){
- var isStepValid = true;
- if(validateStep1() == false){
- isStepValid = false;
- jQuery('#wizard').smartWizard('setError',{stepnum:1,iserror:true});
- }else{
- jQuery('#wizard').smartWizard('setError',{stepnum:1,iserror:false});
- }
- if(validateStep3() == false){
- isStepValid = false;
- jQuery('#wizard').smartWizard('setError',{stepnum:3,iserror:true});
- }else{
- jQuery('#wizard').smartWizard('setError',{stepnum:3,iserror:false});
- }
- if(!isStepValid){
- jQuery('#wizard').smartWizard('showMessage','请修正有错误的步骤,然后继续');
- }
- return isStepValid;
- }
- function validateSteps(step){
- var isStepValid = true;
- // validate step 1
- if(step == 1){
- if(validateStep1() == false ){
- isStepValid = false;
- jQuery('#wizard').smartWizard('showMessage','请选择故障注入对象(勾选上边的树),然后点击下一步.');
- jQuery('#wizard').smartWizard('setError',{stepnum:step,iserror:true});
- }else{
- jQuery('#wizard').smartWizard('setError',{stepnum:step,iserror:false});
- }
- }
- // validate step3
- if(step == 3){
- if(validateStep3() == false ){
- isStepValid = false;
- jQuery('#wizard').smartWizard('showMessage','请将故障参数配置完整,然后点击下一步.');
- jQuery('#wizard').smartWizard('setError',{stepnum:step,iserror:true});
- }else{
- jQuery('#wizard').smartWizard('setError',{stepnum:step,iserror:false});
- }
- }
- if (isStepValid == true) {
- jQuery('#wizard').smartWizard('hideMessage','');
- }
- return isStepValid;
- }
- function validateStep1(){
- var isValid = true;
- // 这里写自己的校验代码
- ...
- return isValid;
- }
- function validateStep3(){
- var isValid = true;
- // 这里写自己的校验代码
- ...
- return isValid;
- }
使用起来还是比较简单的。
转载于:https://blog.51cto.com/memory/1030049