【问题标题】:jquery.steps and validation not working - form content not visible (invisible)jquery.steps 和验证不起作用 - 表单内容不可见(不可见)
【发布时间】:2014-11-20 09:49:05
【问题描述】:

我已经问过一次这个问题,得到了一些有用的回复,将其标记为已回答并应用了所有内容。它看起来似乎奏效了,但遗憾的是它没有。

问题是: 不同步骤字段中的表格为空。 好吧,我无法判断每个步骤是否都是空的,因为我在第一步中看不到并输入任何内容,因此无法进行下一步,因为验证似乎正在工作。

我不知道为什么。我坚持 jquery 步骤页面上给出的示例: http://www.jquery-steps.com/Examples#advanced-form

完全一样的代码但是: 我的表格是空的。它看起来像这样:

我的代码是:

<!DOCTYPE html>
<html>
    <head>
        <title>Demo</title>
        <meta charset="utf-8">
        <script src="/Scripts/jquery-2.1.1.js"></script>
        <script src="/Scripts/jquery.steps.js"></script>
        <link href="/Content/jquery.steps.css" rel="stylesheet">
    </head>

    <body>
        <form id="example-advanced-form" action="#">
            <h3>Account</h3>
            <fieldset>
                <legend>Account Information</legend>

                <label for="userName-2">User name *</label>
                <input id="userName-2" name="userName" type="text" class="required">
                <label for="password-2">Password *</label>
                <input id="password-2" name="password" type="text" class="required">
                <label for="confirm-2">Confirm Password *</label>
                <input id="confirm-2" name="confirm" type="text" class="required">
                <p>(*) Mandatory</p>
            </fieldset>

            <h3>Profile</h3>
            <fieldset>
                <legend>Profile Information</legend>

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

            <h3>Warning</h3>
            <fieldset>
                <legend>You are to young</legend>

                <p>Please go away ;-)</p>
            </fieldset>

            <h3>Finish</h3>
            <fieldset>
                <legend>Terms and Conditions</legend>

                <input id="acceptTerms-2" name="acceptTerms" type="checkbox" class="required"> <label for="acceptTerms-2">I agree with the Terms and Conditions.</label>
            </fieldset>
            </form>
        </body>

    <script>
        var form = $("#example-advanced-form").show();

        form.steps({
            headerTag: "h3",
            bodyTag: "fieldset",
            transitionEffect: "slideLeft",
            onStepChanging: function (event, currentIndex, newIndex) {
                // Allways allow previous action even if the current form is not valid!
                if (currentIndex > newIndex) {
                    return true;
                }
                // Forbid next action on "Warning" step if the user is to young
                if (newIndex === 3 && Number($("#age-2").val()) < 18) {
                    return false;
                }
                // Needed in some cases if the user went back (clean up)
                if (currentIndex < newIndex) {
                    // To remove error styles
                    form.find(".body:eq(" + newIndex + ") label.error").remove();
                    form.find(".body:eq(" + newIndex + ") .error").removeClass("error");
                }
                form.validate().settings.ignore = ":disabled,:hidden";
                return form.valid();
            },
            onStepChanged: function (event, currentIndex, priorIndex) {
                // Used to skip the "Warning" step if the user is old enough.
                if (currentIndex === 2 && Number($("#age-2").val()) >= 18) {
                    form.steps("next");
                }
                // Used to skip the "Warning" step if the user is old enough and wants to the previous step.
                if (currentIndex === 2 && priorIndex === 3) {
                    form.steps("previous");
                }
            },
            onFinishing: function (event, currentIndex) {
                form.validate().settings.ignore = ":disabled";
                return form.valid();
            },
            onFinished: function (event, currentIndex) {
                alert("Submitted!");
            }
        }).validate({
            errorPlacement: function errorPlacement(error, element) { element.before(error); },
            rules: {
                confirm: {
                    equalTo: "#password-2"
                }
            }
        });
     </script>

</html>

有人可以帮忙吗?

【问题讨论】:

    标签: javascript jquery forms validation jquery-steps


    【解决方案1】:

    .content 似乎没有任何宽度(查看上一个屏幕截图右上角的工具提示)。给它一些宽度:

    .wizard > .content {
        ...
        width: 100%;
    }
    

    【讨论】:

    • 好像就是这样!
    • 但它仍然无法在 IE 中运行。你有什么想法为什么? Chrome 现在可以工作,Firefox 一直可以工作,但 IE 不行。
    • 很难说没有东西可以交互。你能减少你的问题并提取代码,以便它可以在 StackOverflow 上运行或使用像 JSFiddle 这样的服务吗?
    • 它现在正在工作.. 不要问为什么,因为我当然不知道答案:)
    【解决方案2】:

    我已经包含了来自原始 Github 源代码的 CSS 文件:

    <link rel="stylesheet" href="css/normalize.css">
    <link rel="stylesheet" href="css/main.css">
    

    并且表单在Chrome和IE中显示。

    【讨论】:

    • 请解释您的答案,代码本身通常不足以显示问题所在。
    猜你喜欢
    • 2015-07-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-26
    • 1970-01-01
    • 1970-01-01
    • 2012-11-06
    相关资源
    最近更新 更多