0

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

在 jquery 向导的页面上,一个名叫“Tommy”的人想出了一段代码来用代码实现bassistance。但由于某种原因,我无法让它工作。它会说是否需要填写该字段等并且下一个按钮不起作用 - 这很好,但是,如果我填写所有字段,下一个按钮仍然不起作用..

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);
            });

        }

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

4

2 回答 2

1

尝试将验证添加到点击事件中

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);
    });
}

更新

或者...尝试从接收时事通讯中删除默认检查?复选框(默认未选中)。click 事件没有附加到下一个按钮,因为该复选框是必需的并已选中,因此stepIsValid为 false 并且 createNextButton 在绑定 click 事件之前返回 false。

于 2010-01-12T16:23:46.190 回答
1

好的,所以我将验证添加到点击事件中,我发现“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 */
于 2010-01-12T23:49:40.067 回答