我有一个使用 jQuery 验证的表单。该表单在除 IE 之外的所有浏览器中都能完美运行(无论 IE 版本如何)。我已经阅读了其他几篇关于让它工作的帖子,但它们没有帮助。他们中的一些人提到去掉尾随逗号;我试过了,但没有用。任何帮助将不胜感激。
这是我的验证码:
<script>
$(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;
}
});
</script>
这是我的 HTmL:
<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript" src="http://ajax.microsoft.com/ajax/jquery.validate/1.7/jquery.validate.min.js"></script>
<style type="text/css">
label.error {
width: 350px;
display: inline;
color: red;
}
</style>
</head>
<div align="center">
<h1>Welcome to the Ojeda Middle School Tutoring Website</h1>
</div>
<p>You can use this page to view tutoring information for the current week.</p>
<p>Please enter a student ID number below then click Submit.</p>
<form id='studentid' class='studentid' action='' method='get'>
<p>
<label for="id">Student ID:</label>
<input type="text" name="id" id="id" /><br>
<button id='submit' class='submit'>Submit</button>
</p>
</form>
<p>
<div id="results"></div>
我什至尝试尽可能简化验证代码。简化后它仍然适用于除 IE 之外的所有浏览器。
简化验证码:
<script>
$(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."}
},
});
</script>