gpt4 book ai didi

javascript - 表单提交按钮在 Google Chrome 中不起作用(jQuery Validate)

转载 作者:行者123 更新时间:2023-11-28 21:21:18 24 4
gpt4 key购买 nike

我在演示页面上使用 jQuery Validate 插件,但由于某种原因,“提交”按钮在 Google Chrome 中不起作用。我怀疑这与自动填充功能有关,但我不确定:

几天来我一直在努力解决这个问题。

链接如下:Contact Form

这是 jQuery 代码的片段。文件中用到的所有js都可以在:combined js code中找到- 初始化代码位于底部。

$(function(){
/* ----- Validation ----- */
$("#contactform").validate({
rules: {
email: {
required: true,
email: true
},
name: "required",
last: "required",
phone: {
required: true,
phoneUS: true,
minlength: 10,
maxlength: 14
},
city: "required",
state: "required",
zip: {
required: true,
minlength: 5,
maxlength: 10
},
testimonial: {
required: true,
minlength: 5
},
security_code: "required"
},

submitHandler: function(form) {
form.submit();
return false;
},

messages: {
email: "<span class='errors'>Please enter a valid email address</span>",
name: {
required: "<span class='errors'>Please enter your first name</span>"
},
last: {
required: "<span class='errors'>Please enter your last name</span>"
},
phone: {
required: "<span class='errors'>Please enter your phone number</span>",
phoneUS: "<span class='errors'>Please enter a valid phone number</span>",
minlength: "<span class='errors'>Phone number too short</span>",
maxlength: "<span class='errors'>Phone number too long</span>"
},
city: "<span class='errors'>Please enter your city</span>",
state: "<span class='errors'>Please choose your state</span>",
zip: {
required: "<span class='errors'>Please enter your zip code</span>",
minlength: "<span class='errors'>Zip Code must be more than 4 characters</span>",
maxlength: "<span class='errors'>Zip Code must be less than 11 characters</span>"
},
testimonial: {
required: "<span class='errors'>Please enter your testimonial</span>",
minlength: "<span class='errors'>Testimonial must be more than 5 characters</span>"
},
security_code: "<span class='errors'>This field is required</span>"
},

errorPlacement: function(error, element) {
if (element.attr('id') != 'security_code_input') {
error.insertAfter(element);
} else {
error.insertAfter($('#sec_code_msg'));
}
}
});


/* ----- Input Masking ----- */
$("#phone").mask("(999) 999-9999");

});

最佳答案

<input name="submit" type="submit" value="Send Now">

通过这一行,您覆盖了表单的“提交”功能并将其替换为按钮。

form.submit = 此按钮。不是事件处理程序。

修复:将按钮命名为其他名称。

关于javascript - 表单提交按钮在 Google Chrome 中不起作用(jQuery Validate),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6310441/

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