gpt4 book ai didi

jquery validate() 在submitHandler中获取当前表单

转载 作者:行者123 更新时间:2023-12-01 00:06:16 25 4
gpt4 key购买 nike

我有一个包含多个表单的页面来验证下面的代码工作正常,但在尝试访问 $.validator 对象以获取存储为“currentForm”的已验证表单选择器/id 的引用时遇到问题

    $("form.validate").each(function(){

$(this).validate({
submitHandler: function(form) {
console.log($(this));
}
});

});

控制台.log ==

[$.validator, init: function, selector: "", jquery: "1.4.2", size: function, toArray: function…]
0: $.validator
containers: c.fn.c.init[0]
currentElements: c.fn.c.init[12]
currentForm: form#thisForm1.validate
...

为什么 - $.validator.currentForm 没有给我 currentForm 的值?

我尝试过 validator.currentForm.id 和 validator.currentForm 以及许多其他组合。关于如何在我的submitHandler 中使用该值来引用子表单的任何想法。

最佳答案

您可以使用传递给 submitHandler 方法的 form 参数,它引用提交的表单元素。请参阅 submitHandler 的文档

$("form.validate").each(function(){

$(this).validate({
submitHandler: function(form) {
console.log(form, $(form));
}
});

});

关于jquery validate() 在submitHandler中获取当前表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20485769/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com