首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Jquery-步骤库和GoToStep函数

Jquery-步骤库和GoToStep函数
EN

Stack Overflow用户
提问于 2014-02-10 09:02:14
回答 1查看 1.9K关注 0票数 0

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

代码语言:javascript
复制
/**
 * 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;
}

我想使用这个函数,所以每次用户在wizzard中在step 3上提交表单时,他将不再被重定向到step 1,而是停留在step 3

贝娄是我的剧本:

代码语言:javascript
复制
          $("#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);"?>

但是我认为我执行这个函数很糟糕,因为它不起作用。有人能帮我写这个剧本吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-02-10 13:30:41

我自己想出来的。问题很容易解决,问题是如何正确设置属性startIndex,例如:

代码语言:javascript
复制
<?
if (Env::value('generate'))
    echo "startIndex: \"2\",";
?> 
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21672750

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档