0

jquery.steps.js我在库中遇到了函数:

/**
 * Routes to a specific step by a given index.
 *
 * @static
 * @private
 * @method goToStep
 * @param wizard {Object} The jQuery wizard object
 * @param options {Object} Settings of the current wizard
 * @param state {Object} The state container of the current wizard
 * @param index {Integer} The position (zero-based) to route to
 * @return {Boolean} Indicates whether the action succeeded or failed
 **/
function goToStep(wizard, options, state, index)
{
    if (index < 0 || index >= state.stepCount)
    {
        throwError(_indexOutOfRangeErrorMessage);
    }

    if (options.forceMoveForward && index < state.currentIndex)
    {
        return;
    }

    var oldIndex = state.currentIndex;
    if (wizard.triggerHandler("stepChanging", [state.currentIndex, index]))
    {
        // Save new state
        state.currentIndex = index;
        saveCurrentStateToCookie(wizard, options, state);

        // Change visualisation
        refreshStepNavigation(wizard, options, state, oldIndex);
        refreshPagination(wizard, options, state);
        loadAsyncContent(wizard, options, state);
        startTransitionEffect(wizard, options, state, index, oldIndex);

        wizard.triggerHandler("stepChanged", [index, oldIndex]);
    }
    else
    {
        wizard.find(".steps li").eq(oldIndex).addClass("error");
    }

    return true;
}

我想使用这个功能,所以每次用户step 3在向导中提交表单时,他不会再次被重定向到,step 1而是留在step 3.

贝娄是我的脚本:

          $("#wizard-2").steps({
                headerTag: "h3",
                bodyTag: "section",
                transitionEffect: "slideLeft",
                onStepChanging: function (event, currentIndex, newIndex)
                {
                    $("#form-2").validate().settings.ignore = ":disabled,:hidden";
                    return $("#form-2").valid();
                },
                onFinishing: function (event, currentIndex)
                {
                    $("#form-2").validate().settings.ignore = ":disabled";
                    return $("#form-2").valid();
                },
                onFinished: function (event, currentIndex)
                {
                    $('<input />').attr('type', 'hidden')
                    .attr('name','ssl')
                    .attr('value', 'true')
                    .appendTo('#form-2');
                    document.getElementById("form-2").submit();
                }
            });
            <? if ($_POST['submit'])
                   echo "$(\"wizard-2\").goToStep(this, ,3,0);"?>

但我相信我对这个功能的执行非常糟糕,因为它不起作用。任何人都可以帮我解决这个脚本吗?

4

1 回答 1

1

我自己想通了。问题很简单,它是关于正确设置属性startIndex,如:

<?
if (Env::value('generate'))
    echo "startIndex: \"2\",";
?> 
于 2014-02-10T13:30:41.607 回答