如何在 jquery.smart 向导完成按钮上触发?

r.r*_*r.r 1 jquery submit request smart-wizard

我在 jquery 中很新。这是来自智能向导的jquery :

/ Default Properties and Events
    $.fn.smartWizard.defaults = {
        selected: 0,  // Selected Step, 0 = first step
        keyNavigation: true, // Enable/Disable key navigation(left and right keys are used if enabled)
        enableAllSteps: false,
        transitionEffect: 'fade', // Effect on navigation, none/fade/slide/slideleft
        contentURL:null, // content url, Enables Ajax content loading
        contentCache:true, // cache step contents, if false content is fetched always from ajax url
        cycleSteps: false, // cycle step navigation
        enableFinishButton: false, // make finish button enabled always
        hideButtonsOnDisabled: false, // when the previous/next/finish buttons are disabled, hide them instead?
        errorSteps:[],    // Array Steps with errors
        labelNext:'Next',
        labelPrevious:'Previous',
        labelFinish:'Finish',
        noForwardJumping: false,
        ajaxType: "POST",
        onLeaveStep: null, // triggers when leaving a step
        onShowStep: null,  // triggers when showing a step
        onFinish: null,  // triggers when Finish button is clicked
        includeFinishButton : true   // Add the finish button
    };

})(jQuery);



<script type="text/javascript">
        $(document).ready(function() {
            // Smart Wizard         
            $('#wizard').smartWizard({
                onLeaveStep: leaveAStepCallback,
                onFinish: onFinishCallback
            });

            function leaveAStepCallback(obj, context) {
                debugger;
                alert("Leaving step " + context.fromStep + " to go to step " + context.toStep);
                return validateSteps(context.fromStep); // return false to stay on step and true to continue navigation 
            }

            function onFinishCallback(objs, context) {

                debugger;
                if (validateAllSteps()) {
                    $('form').submit();
                }
            }

            // Your Step validation logic
            function validateSteps(stepnumber) {
                debugger;
                var isStepValid = true;
                // validate step 1
                if (stepnumber == 1) {
                    // Your step validation logic
                    // set isStepValid = false if has errors
                }
                // ...      
            }
            function validateAllSteps() {
                debugger;
                var isStepValid = true;
                // all step validation logic     
                return isStepValid;
            }
        });
</script>
Run Code Online (Sandbox Code Playgroud)

我需要一些 onFinish 的功能,我可以在其中发送带有许多参数的请求。怎么做?

mad*_*dhu 5

首先从https://github.com/mstratman/jQuery-Smart-Wizard下载 smartWizard.js, 然后将其添加到您的工作区并在您的 html/jsp 中提供参考。

<script type="text/javascript" src="js/jquery.smartWizard-2.1.js"></script>
Run Code Online (Sandbox Code Playgroud)

然后,

<script type="text/javascript">
$(document).ready(function(){
    // Smart Wizard     
    $('#wizard').smartWizard();
    //$('#range').colResizable();

    function onFinishCallback(){
        $('#wizard').smartWizard('showMessage','Finish Clicked');
    } 
});
</script>
Run Code Online (Sandbox Code Playgroud)

然后在 jquery.smartWizard-2.1.js 中搜索 onFinish,尝试给出警报,然后你想添加的任何内容都可以直接添加到 .js 文件中。