jQuery验证强制双击“提交"以提交提交到thickbox的表单

编程入门 行业动态 更新时间:2024-10-27 20:36:46
本文介绍了jQuery验证强制双击“提交"以提交提交到thickbox的表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我必须在表单上单击两次提交按钮,以便在添加jQuery验证后提交表单.还有其他与此相关的帖子,但是这些解决方案对我不起作用,因为我的表单提交了一个厚框弹出窗口,该弹出窗口需要GET方法和某些变量才能传递.我正在使用jquery.validate/1.8/jquery.validate.min.js和jquery/1.5.2/jquery.min.js.我没有包括规则,因为这只是我正在使用数字"类进行验证的一个字段(数量),以验证是否存在一个值并且它是一个数字.

I have to click the submit button twice on my form in order to submit it after adding jQuery validation. There are other posts regarding this but those solutions are not working for me as my form submits to a thickbox popup which requires a GET method and certain variables to be passed. I am using jquery.validate/1.8/jquery.validate.min.js and jquery/1.5.2/jquery.min.js. I am not including rules as it is just one field (quantity) that I am validating with class 'number' to verify there is a value and it is a number.

这是我的代码:

$(document).ready(function(){ // validate the form when it is submitted $("form.cart_form").validate({ //adding submitHandler results in having to click twice submitHandler: function(form) { $("form.cart_form").submit(function() { var title = ""; var productID = $("select[name=product_id]", this).val(); var quantity = $("input[name=quantity]", this).val(); var url = "../cart/add-to-cart.php?product_id=" + productID + "&quantity=" + quantity + "&TB_iframe=true&height=300&width=600"; tb_show(title, url, false); // submit the form // return false to prevent normal browser submit & page navigation return false; }); } }); });

我绝不是jQuery专家,所以在此先感谢您提供的任何解决方案.

I am by no means a jQuery expert, so thank you in advance for any solutions you can provide.

推荐答案

您的代码出现了太多的递归错误:$("form.cart_form").submit()触发了另一轮验证,从而导致了对commitHandler和递归的另一次调用.将其替换为form.submit()

Your code in a too-much-recursion error: $("form.cart_form").submit() triggers another round of validation, resulting in another call to submitHandler, and voila, recursion. Replace that with form.submit()

$(document).ready(function(){ // validate the form when it is submitted $("form.cart_form").validate({ //adding submitHandler results in having to click twice submitHandler: function(form) { form.submit(function() { var title = ""; var productID = $("select[name=product_id]", this).val(); var quantity = $("input[name=quantity]", this).val(); var url = "../cart/add-to-cart.php?product_id=" + productID + "&quantity=" + quantity + "&TB_iframe=true&height=300&width=600"; tb_show(title, url, false); // submit the form // return false to prevent normal browser submit & page navigation return false; }); } }); });

更多推荐

jQuery验证强制双击“提交"以提交提交到thickbox的表单

本文发布于:2023-10-09 17:56:39,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1476381.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:双击   表单   jQuery   thickbox   quot

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!