繁体   English   中英

jQuery表单向导验证

[英]jquery form wizard validation

我正在尝试使用jquery表单向导( http://www.jankoatwarpspeed.com/post/2009/09/28/webform-wizard-jquery.aspx )来实现验证脚本(基础)。问题。

在jquery向导的页面上,一个名为“ Tommy”的家伙提出了一段代码,以实现该代码的低音增强功能。 但是由于某种原因,我无法使其正常工作。 出现这样的说法:如果需要填写该字段等,而下一个按钮不起作用-很好,但是,如果我填写所有字段,则下一个按钮仍然不起作用。

function createNextButton(i) {

            var stepName = "step" + i;
            $("#" + stepName + "commands").append("<a href='#' id='" + stepName + "Next' class='next'>Next ></a>");

            /* VALIDATION */
            if (options.validationEnabled) {
                var stepIsValid = true; 
                $("#" + stepName + " :input").each(function(index) { 
                    stepIsValid = !element.validate().element($(this)) && stepIsValid;
                });
                if (!stepIsValid) {
                    return false; 
                }
            }
            /* END VALIDATION */

            $("#" + stepName + "Next").bind("click", function(e) {
                $("#" + stepName).hide();
                $("#step" + (i + 1)).show();
                if (i + 2 == count)
                    $(submmitButtonName).show();
                selectStep(i + 1);
            });

        }

有人可以帮我解决这个问题吗? :)

尝试将验证添加到click事件中

function createNextButton(i) {
    var stepName = "step" + i;
    $("#" + stepName + "commands").append("<a href='#' id='" + stepName + "Next' class='next'>Next ></a>");

    $("#" + stepName + "Next").bind("click", function(e) {
        /* VALIDATION */
        if (options.validationEnabled) {
            var stepIsValid = true; 
            $(this).closest("fieldset").find(":input").each(function(index) { 
                stepIsValid = element.validate().element($(this)) && stepIsValid;
            });
            if (!stepIsValid) {
                return false; 
            }
        }
        /* END VALIDATION */

        $("#" + stepName).hide();
        $("#step" + (i + 1)).show();
        if (i + 2 == count)
            $(submmitButtonName).show();
        selectStep(i + 1);
    });
}

更新

或者...尝试从“ 接收通讯”中删除默认检查吗? 复选框(默认情况下未选中)。 单击事件不会附加到下一个按钮,因为必须选中该复选框并选中它,因此stepIsValid为false,并且在绑定单击事件之前createNextButton返回false。

好的,所以我将验证添加到click事件中,然后我发现实际上存在“ element.validate()。element($(this))&& stepIsValid”。如果其他任何人正在使用此方法并遇到相同的问题,则解决方案是:

/* VALIDATION */
                if (options.validationEnabled) {
                    var stepIsValid = true;
                    $("#"+stepName+" :input").each(function(index) {
                        checkMe = element.validate().element($(this));
                        //stepIsValid = !element.validate().element($(this)) && stepIsValid;
                        stepIsValid = checkMe && stepIsValid;
                    });
                    //alert("stepIsValid === "+stepIsValid);
                    if (!stepIsValid) {
                        return false;
                    };
                }; 
                /* END VALIDATION */

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM