私はjQueryの初心者で、簡単なhtmlページを作成しようとしています。ページは正常にレンダリングされ、jQueryを使用して正しく検証/動作しますが、すべてが有効な場合、[送信]ボタンをクリックしてもページは送信されません。私のhtmlファイルの完全なページコードは以下の通りです。フォームの送信が拒否されるのはなぜですか?
<html>
<head>
<title>jQuery UI Example Page</title>
<link type="text/css" href="css/cupertino/jquery-ui-1.8.21.custom.css" rel="stylesheet" />
<script type="text/javascript" src="js/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="js/jquery-ui-1.8.21.custom.min.js"></script>
<script type="text/javascript" src="http://jzaefferer.github.com/jquery-validation/jquery.validate.js"></script>
<script type="text/javascript">
jQuery.validator.setDefaults({
debug: true,
success: "valid"
}); ;
</script>
<script>
$.validator.addMethod(
"regex",
function (value, element, regexp) {
var re = new RegExp(regexp);
return this.optional(element) || re.test(value);
},
"Please check your input."
);
</script>
<script type="text/javascript">
/**
* @author GeekTantra
* @date 24 September 2009
*/
/*
* This functions checks where an entered date is valid or not.
* It also works for leap year feb 29ths.
* @year: The Year entered in a date
* @month: The Month entered in a date
* @day: The Day entered in a date
*/
function isValidDate(year, month, day) {
var date = new Date(year, (month - 1), day);
var DateYear = date.getFullYear();
var DateMonth = date.getMonth();
var DateDay = date.getDate();
if (DateYear == year && DateMonth == (month - 1) && DateDay == day)
return true;
else
return false;
}
/*
* This function checks if there is at-least one element checked in a group of
* check-boxes or radio buttons.
* @id: The ID of the check-box or radio-button group
*/
function isChecked(id) {
var ReturnVal = false;
$("#" + id).find('input[type="radio"]').each(function () {
if ($(this).is(":checked"))
ReturnVal = true;
});
$("#" + id).find('input[type="checkbox"]').each(function () {
if ($(this).is(":checked"))
ReturnVal = true;
});
return ReturnVal;
}
</script>
<script type="text/javascript">
$.validator.addMethod(
"totalValidationDate",
function (value, element) {
return isValidDate(parseInt(value.split('/')[2]), parseInt(value.split('/')[0]), parseInt(value.split('/')[1])) || this.optional(element);
},
"Please enter a date in the format mm/dd/yyyy"
);
</script>
<script>
$(document).ready(function () {
$("#commentForm").validate({
rules: {
date1: {
required: true,
totalValidationDate: true
},
textBox1: {
regex: "^[a-zA-Z'.\\s]{1,40}$"
}
}
});
});
</script>
<script type="text/javascript">
$(document).ready(function () {
$("#date1").datepicker();
});
</script>
</head>
<body>
<form id="commentForm" method="get" action="http://www.yahoo.com">
<input type="text" name="date1" id="date1" />
<input type="text" name="textBox1" id="textBox1" />
<input type="submit" value="Submit" id="btnSubmit"/>
</form>
</body>
</html>