jquery表单向导validation
我正在尝试使用jquery表单向导( http://www.jankoatwarpspeed.com/post/2009/09/28/webform-wizard-jquery.aspx )实现validation脚本(bassistance)但我有一些问题。
在jquery向导的页面上,一个名为“Tommy”的人想出了一段代码来实现代码的低音。 但由于某种原因,我无法让它发挥作用。 它出现了,如果该字段需要填写等,下一个按钮不起作用 – 这很好,但是,如果我填写所有字段,下一个按钮仍然无法工作..
function createNextButton(i) { var stepName = "step" + i; $("#" + stepName + "commands").append("Next >"); /* 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); }); }
有人能帮我解决这个问题吗? 🙂
好的,所以我将validation添加到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 */
尝试将validation添加到click事件中
function createNextButton(i) { var stepName = "step" + i; $("#" + stepName + "commands").append("Next >"); $("#" + 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。