IE中的jQuery Validate插件失败

我有一个表单,我正在使用jQueryvalidation。 除了IE之外,该表单在每个浏览器中都能完美运行(无论哪个版本的IE)。 我已经阅读了其他一些关于让它上class的post,但他们没有帮助。 他们中的一些人提到摆脱尾随的逗号; 我试过了,它没用。 任何帮助将不胜感激。

这是我的validation码:

 $(document).ajaxStop(function(){ setTimeout("window.location = 'index.php'",60000); }); $.validator.addMethod("zero", function(input, element) { return ! input || input.match(/^[0]/); }, "This field must start with a zero"); $("#studentid").validate({ debug: false, rules: { id: {required: true, zero: true} }, messages: { id: {required: "Please enter the student's ID number.", zero: "Student ID must start with a zero."} }, submitHandler: function(form) { $.ajax({ url: 'tutoring.php', type: 'POST', data: $("#studentid").serialize(), success: function(data) { $("#id").val(""); $("#results").empty(); $("#results").append(data); } }); return false; } });  

这是我的HTmL:

      label.error { width: 350px; display: inline; color: red; }   

Welcome to the Ojeda Middle School Tutoring Website

You can use this page to view tutoring information for the current week.

Please enter a student ID number below then click Submit.


我甚至尝试尽可能地简化validation代码。 在简化它之后,它仍然适用于除IE以外的所有浏览器。

简化的validation码:

  $(document).ajaxStop(function(){ setTimeout("window.location = 'index.php'",60000); }); $("#studentid").validate({ debug: false, rules: { id: {required: true} }, messages: { id: {required: "Please enter the student's ID number."} }, });  

你的代码:

 $.validator.addMethod("zero", function(input, element) { ... }); $("#studentid").validate({ // options }); 

您应该将代码包装在DOM中,并按照下面的演示进行操作。

 $(document).ready(function() { $.validator.addMethod("zero", function(input, element) { ... }); $("#studentid").validate({ // <-- initialize the plugin once // options }); }); 

工作演示: http : //jsfiddle.net/HNK6w/

如您所见,它在Windows 7上的Internet Explorer 9中运行...

在此处输入图像描述

IE使用额外的逗号不能很好地播放。

请注意messages属性后面的额外逗号。 取下它赢了。

 $("#studentid").validate({ debug: false, rules: { id: {required: true} }, messages: { id: {required: "Please enter the student's ID number."} }, <--------------------