简体   繁体   English

jQuery重置对话框中表单上的验证

[英]jQuery reset validation on a form in a dialog

I've been struggling to reset a form within a dialog window upon close. 我一直在努力在关闭时在对话框窗口中重置一个表单。 My form is using jQuery validate and I've tried to use the documented resetForm() function, but no luck. 我的表单是使用jQuery验证,我试图使用记录的resetForm()函数,但没有运气。

Below are two attempts on how I am trying to achieve clearing the form upon the user hitting "Close". 以下是我尝试在用户点击“关闭”时清除表单的两次尝试。 Neither are working. 两者都没有工作。

Here's the jsFiddle: http://jsfiddle.net/FjT7T/6/ 这是jsFiddle: http//jsfiddle.net/FjT7T/6/

$("#myDialog").dialog({
    autoOpen: false,
    close: function(event, ui) {
        // Attempt to reset the form using JQuery validates resetForm(), not working.
        var validator = $("#myForm").validate();
        validator.resetForm();
        // Attempt to reset the form and remove the error classes, not working either. 
        $(this).closest("form")[0].reset().removeClass("error");
    }
});

Have you tried plain javascript reset? 你试过普通的javascript重置吗?

document.getElementById('myForm').reset();

Or even jQuery, but with the form's id: 甚至是jQuery,但是使用表单的id:

$("#myForm").reset();

And to remove the class, why note use the #id 要删除该类,为什么要注意使用#id

$("#myForm").removeClass("error");

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

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