How can I prevent this duplication without making changes to the form's HTML code or to check_theForm(), seeing as these are generated by legacy back-end code that I can't change?推荐答案当您拥有 onsubmit ="x()" 时,可以使用$("#id").attr("onsubmit", null);允许您完全控制自己的事件处理程序.allowing you full control without your own event handler.在这种情况下,给出:$("#theForm").attr("onsubmit", null);$('#theForm').submit(function(event) { event.preventDefault(); grecaptcha.ready(function() { grecaptcha.execute('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', {action: 'contactForm'}).then(function(token) { $('#theForm').prepend('<input type="hidden" name="token" value="' + token + '">'); $('#theForm').prepend('<input type="hidden" name="action" value="contactForm">'); if (check_theForm()) $('#theForm').unbind('submit').submit(); });; });}); 这篇关于将表单onsubmit参数与jquery提交事件处理程序结合起来的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 07-15 11:26