Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/382.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Jquery步骤:如果您之前跳过了一个步骤,那么使用无端循环返回stucks_Javascript_Jquery_Jquery Steps - Fatal编程技术网

Javascript Jquery步骤:如果您之前跳过了一个步骤,那么使用无端循环返回stucks

Javascript Jquery步骤:如果您之前跳过了一个步骤,那么使用无端循环返回stucks,javascript,jquery,jquery-steps,Javascript,Jquery,Jquery Steps,我正在实施 在这里,如果年龄小于18岁,我需要跳过一步, 这是一个类似的例子,在上面的链接中工作, 当我试图实现同样的目标时, 跳过一个步骤很好,但一旦我需要返回上一个按钮的点击,JS就会被无端循环卡住 我为同样的目标创建了JSFIDLE 这是JS $(function () { $("#form-3").steps({ bodyTag: "fieldset", headerTag: "h1", onStepChanging: funct

我正在实施

在这里,如果年龄小于18岁,我需要跳过一步, 这是一个类似的例子,在上面的链接中工作, 当我试图实现同样的目标时, 跳过一个步骤很好,但一旦我需要返回上一个按钮的点击,JS就会被无端循环卡住

我为同样的目标创建了JSFIDLE

这是JS

$(function () {

    $("#form-3").steps({
        bodyTag: "fieldset",
        headerTag: "h1",
        onStepChanging: function (event, currentIndex, newIndex) {
            if (currentIndex > newIndex) {
                return true;
            }

            if (newIndex === 3 && Number($("#age").val()) < 18) {
                return false;
            }

            var form = $(this);

            if (currentIndex < newIndex) {
                $("#form-3 .body:eq(" + newIndex + ") label.error", form).remove();
                $("#form-3 .body:eq(" + newIndex + ") .error", form).removeClass("error");
            }

            return true;
        },
        onStepChanged: function (event, currentIndex, priorIndex) {
            if (currentIndex === 2 && Number($("#age").val()) >= 18) {
                $(this).steps("next");
            }

            if (currentIndex === 2 && priorIndex === 3) {
                $(this).steps("previous");
            }
        },
        onFinishing: function (event, currentIndex) {
            return true;
        },
        onFinished: function (event, currentIndex) {
            var form = $(this);
            form.submit();
        }
    })
});
$(函数(){
$(“#表格3”)。步骤({
bodyTag:“字段集”,
头像:“h1”,
onStepChanging:函数(事件、currentIndex、newIndex){
如果(currentIndex>newIndex){
返回true;
}
if(newIndex==3&&Number($(“#age”).val())<18){
返回false;
}
变量形式=$(此);
如果(当前索引<新索引){
$(“#form-3.body:eq(“+newIndex+”)label.error”,form.remove();
$(“#form-3.body:eq(“+newIndex+”).error”,form).removeClass(“error”);
}
返回true;
},
onStepChanged:函数(事件、当前索引、优先级索引){
如果(currentIndex==2&&Number($(“#年龄”).val())>=18){
$(本)。步骤(“下一步”);
}
如果(currentIndex==2&&PrioriIndex==3){
$(本)。步骤(“上一步”);
}
},
onFinishing:函数(事件、当前索引){
返回true;
},
onFinished:函数(事件、当前索引){
变量形式=$(此);
表单提交();
}
})
});
这里是HTML

<form id="form-3" action="#">
        <h1 class="noDisplay">Account</h1>
        <fieldset>
            <legend>Account Information</legend>
            <h3> Your Information</h3>
            <ul>
                <li>
                    <div><label for="userName">User name *</label></div>
                    <div><input id="userName" name="userName" type="text" class="required" data-msg-required="Username Required!"/></div>
                    <div class="cell"><div class="registerError"></div></div>
                </li>
                <li>
                    <div><label for="password">Password *</label></div>
                    <div><input id="password" name="password" type="text" class="required" data-msg-required="Password Required!"></div>
                    <div class="cell"><div class="registerError"></div></div>
                </li>
                <li>
                    <div><label for="confirm">Confirm Password *</label></div>
                    <div><input id="confirm" name="confirm" type="text" class="required" data-msg-required="Confirm Password Required!"></div>
                    <div class="cell"><div class="registerError"></div></div>
                </li>   
            </ul>
            <p>(*) Mandatory</p>
        </fieldset>

        <h1 class="noDisplay">Profile</h1>
        <fieldset>
            <legend>Profile Information</legend>
            <h3> Your Information</h3>
            <label for="name">First name *</label>
            <input id="name" name="name" type="text" class="required">
            <label for="surname">Last name *</label>
            <input id="surname" name="surname" type="text" class="required">
            <label for="email">Email *</label>
            <input id="email" name="email" type="text" class="required email">
            <label for="address">Address</label>
            <input id="address" name="address" type="text">
            <label for="age">Age (The warning step will show up if age is less than 18) *</label>
            <input id="age" name="age" type="text" class="required number">
            <p>(*) Mandatory</p>
        </fieldset>

        <h1 class="noDisplay">Warning</h1>
        <fieldset>
            <legend>You are to young</legend>
            <h3> Your Information</h3>
            <p>Please go away ;-)</p>
        </fieldset>

        <h1 class="noDisplay">Finish</h1>
        <fieldset>
            <legend>Terms and Conditions</legend>
            <h3> Your Information</h3>
            <input id="acceptTerms" name="acceptTerms" type="checkbox" class="required"> <label for="acceptTerms">I agree with the Terms and Conditions.</label>
        </fieldset>
    </form>

账户
帐户信息
你的信息
  • 用户名*
  • 密码*
  • 确认密码*
(*)强制性

轮廓 配置文件信息 你的信息 名字* 姓* 电子邮件* 地址 年龄(如果年龄小于18岁,则会显示警告步骤)* (*)强制性

警告 你太年轻了 你的信息 请走开;-)

完成 条款和条件 你的信息 我同意这些条款和条件。

我观察到currentIndex和newIndex参数没有得到正确的值,但我不明白为什么?

在onStepChanged中,有两条语句的顺序错误,因此我将其更改为现在可以正常工作

我已经在博客文章中修复了它。但是你自己试试看

下面是固定的JS代码

onStepChanged: function (event, currentIndex, priorIndex)
{
    // Suppress (skip) "Warning" step if the user is old enough and wants to the previous step.
    if (currentIndex === 2 && priorIndex === 3)
    {
        $(this).steps("previous");
        return;
    }

    // Suppress (skip) "Warning" step if the user is old enough.
    if (currentIndex === 2 && Number($("#age").val()) >= 18)
    {
        $(this).steps("next");
    }
}