jQuery Steps – 重置向导,无需重新加载页面

我正在使用jQuery步骤( https://github.com/rstaib/jquery-steps/wiki )来创建一步一步的表单给用户填写。 它工作得很好,但我需要能够重置它。 一旦用户提交了表单(使用ajax以便页面不刷新),我想呈现一个用户新鲜的向导。

有没有办法重置向导? 或者也许重新加载而不重新加载页面?

通过在此处向解决方案添加几行代码,我可以重置我的jQuery步骤向导,还有一些额外的代码行来删除css类。 在调用此函数之前或之后,您仍需要使用首选库重置表单。

$.fn.steps.reset = function () { var wizard = this, options = getOptions(this), state = getState(this); goToStep(wizard, options, state, 0); for (i = 1; i < state.stepCount; i++) { var stepAnchor = getStepAnchor(wizard, i); stepAnchor.parent().removeClass("done")._enableAria(false); } }; 

您可以使用jQuery Form Plugin ,重置或清除表单非常简单

 $('#myFormId').resetForm(); 

要么

 $('#myFormId').clearForm(); 

或者只有特殊字段

 $('#myFormId .specialFields').clearFields(); 

自定义重置function的小修正:

 $.fn.steps.reset = function () { var wizard = this, options = getOptions(this), state = getState(this); if(state.currentIndex>0) { goToStep(wizard, options, state, 0); for (i = 1; i < state.stepCount; i++) { var stepAnchor = getStepAnchor(wizard, i); stepAnchor.parent().removeClass("done")._enableAria(false); } } }; 

我添加了一个if,以防你尝试在第0步重置。

 You can user this function after submitting your form: function resetForm(id_form){ $("#" + id_form).find('input[type="text"]').val(''); $("#" + id_form).find('input[type="password"]').val(''); $("#" + id_form).find('input[type="checkbox"]').removeAttr("checked"); $("#" + id_form).find('select option').removeAttr("selected"); $("#" + id_form).find('textarea').val(''); } Best regards!