javascript中有没有判断日期的函数? function isdate(str){ var dt = new Date(str); if (isNaN(dt)) return false; else return true;} 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 to karma: 能不能再回答一下,满足我上面条件的呢?对于javascript我可是有些了解而已,现在给朋友做个网站,又不想用vbscript,所以…… 如果分不够,再加…… <HTML><HEAD><META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0"><META content="text/html; charset=gb2312" http-equiv=Content-Type><TITLE>checkdata</TITLE><script language="javascript"><!--// PURPOSE: Check to see if the string passed in is a valid time.// A valid time is defined as a string which is postfixed with either// "PM" or "AM". Next it checks to see if there is a colon in the// string. If there is, it makes sure that at least one digit preceeds// it and two proceed it.function chkdate(objName) {var strDatestyle = "US"; //United States date stylevar strDate;var strDateArray;var strDay;var strMonth;var strYear;var intday;var intMonth;var intYear;var booFound = false;var datefield = objName;var strSeparatorArray = new Array("-"," ","/",".");var intElementNr;var err = 0;var strMonthArray = new Array(12);strMonthArray[0] = "Jan";strMonthArray[1] = "Feb";strMonthArray[2] = "Mar";strMonthArray[3] = "Apr";strMonthArray[4] = "May";strMonthArray[5] = "Jun";strMonthArray[6] = "Jul";strMonthArray[7] = "Aug";strMonthArray[8] = "Sep";strMonthArray[9] = "Oct";strMonthArray[10] = "Nov";strMonthArray[11] = "Dec";strDate = datefield.value;if (strDate.length==0) {return false;}for (intElementNr = 0; intElementNr < strSeparatorArray.length; intElementNr++) {if (strDate.indexOf(strSeparatorArray[intElementNr]) != -1) {strDateArray = strDate.split(strSeparatorArray[intElementNr]);if (strDateArray.length != 3) {return false;}else {strDay = strDateArray[0];strMonth = strDateArray[1];strYear = strDateArray[2]; if (strYear.length>4){ return false; }} }}// US styleif (strDatestyle == "US") {strTemp = strDay;strDay = strMonth;strMonth = strTemp;}intday = parseInt(strDay, 10);if (isNaN(intday)) {return false;}intMonth = parseInt(strMonth, 10);if (isNaN(intMonth)) {for (i = 0;i<12;i++) {if (strMonth.toUpperCase() == strMonthArray[i].toUpperCase()) {intMonth = i+1;strMonth = strMonthArray[i];i = 12; }}if (isNaN(intMonth)) {return false; }}intYear = parseInt(strYear, 10);if (isNaN(intYear)) {return false;}if (intMonth>12 || intMonth<1) {return false;}if ((intMonth == 1 || intMonth == 3 || intMonth == 5 || intMonth == 7 || intMonth == 8 || intMonth == 10 || intMonth == 12) && (intday > 31 || intday < 1)) {return false;}if ((intMonth == 4 || intMonth == 6 || intMonth == 9 || intMonth == 11) && (intday > 30 || intday < 1)) {return false;}if (intMonth == 2) {if (intday < 1) {return false;}if (LeapYear(intYear) == true) {if (intday > 29) {return false;}}else {if (intday > 28) {return false;}}}if (strDatestyle == "US") {datefield.value = strMonthArray[intMonth-1] + " " + intday+" " + strYear;}else {datefield.value = intday + " " + strMonthArray[intMonth-1] + " " + strYear;}return true;}function LeapYear(intYear) {if (intYear % 100 == 0) {if (intYear % 400 == 0) { return true; }}else {if ((intYear % 4) == 0) { return true; }}return false;}function checkdata(){var strdate=document.form1.strdate;if (chkdate(strdate)==false){ alert("The date is Invalid!") document.form1.strdate.select(); document.form1.strdate.focus(); return false;}}//--></script></HEAD><BODY onload="javascript:test()"><form name="form1" method="post" action=""> <table width="100%" border="0"> <tr> <td width="45%"> <div align="right">Please input the Date:</div> </td> <td width="55%"> <input type="text" name="strdate"> </td> </tr> <tr> <td colspan="2"> <div align="center"> </div> </td> </tr> <tr> <td colspan="2"> <div align="center"> <input type="button" name="Button" value="Submit" onClick="javascript:checkdata()" style="cursor:hand"> </div> </td> </tr> </table></form></BODY></HTML> js绘制任意位置和方向的直线 >>>>>>>jstree异步树勾选问题 JavaScript可以操作浏览器的缓冲区吗? 关于js的模态对话框问题 用JS写个文件下载方法 。。。 或者前台html控件onclick事件执行后台下载方法 。。。 js如何从一个日期中减掉几个小时 请教一个正则表达式的问题 obj.style.display = "" 是指什么意思啊? 简单问题,解决马上给分 用JavaScript如何写另存为? 一个奇怪的问题求解 不知在javascipt中这段代码有何问题?
能不能再回答一下,满足我上面条件的呢?对于javascript我可是有些了解而已,现在给朋友做个网站,又不想用vbscript,所以……
如果分不够,再加……
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<META content="text/html; charset=gb2312" http-equiv=Content-Type>
<TITLE>checkdata</TITLE>
<script language="javascript">
<!--
// PURPOSE: Check to see if the string passed in is a valid time.
// A valid time is defined as a string which is postfixed with either
// "PM" or "AM". Next it checks to see if there is a colon in the
// string. If there is, it makes sure that at least one digit preceeds
// it and two proceed it.function chkdate(objName) {
var strDatestyle = "US"; //United States date style
var strDate;
var strDateArray;
var strDay;
var strMonth;
var strYear;
var intday;
var intMonth;
var intYear;
var booFound = false;
var datefield = objName;
var strSeparatorArray = new Array("-"," ","/",".");
var intElementNr;
var err = 0;
var strMonthArray = new Array(12);
strMonthArray[0] = "Jan";
strMonthArray[1] = "Feb";
strMonthArray[2] = "Mar";
strMonthArray[3] = "Apr";
strMonthArray[4] = "May";
strMonthArray[5] = "Jun";
strMonthArray[6] = "Jul";
strMonthArray[7] = "Aug";
strMonthArray[8] = "Sep";
strMonthArray[9] = "Oct";
strMonthArray[10] = "Nov";
strMonthArray[11] = "Dec";
strDate = datefield.value;
if (strDate.length==0) {
return false;
}
for (intElementNr = 0; intElementNr < strSeparatorArray.length; intElementNr++) {
if (strDate.indexOf(strSeparatorArray[intElementNr]) != -1) {
strDateArray = strDate.split(strSeparatorArray[intElementNr]);
if (strDateArray.length != 3) {
return false;
}
else {
strDay = strDateArray[0];
strMonth = strDateArray[1];
strYear = strDateArray[2];
if (strYear.length>4){
return false;
}
}
}
}// US style
if (strDatestyle == "US") {
strTemp = strDay;
strDay = strMonth;
strMonth = strTemp;
}
intday = parseInt(strDay, 10);
if (isNaN(intday)) {
return false;
}
intMonth = parseInt(strMonth, 10);
if (isNaN(intMonth)) {
for (i = 0;i<12;i++) {
if (strMonth.toUpperCase() == strMonthArray[i].toUpperCase()) {
intMonth = i+1;
strMonth = strMonthArray[i];
i = 12;
}
}
if (isNaN(intMonth)) {
return false;
}
}
intYear = parseInt(strYear, 10);
if (isNaN(intYear)) {
return false;
}
if (intMonth>12 || intMonth<1) {
return false;
}
if ((intMonth == 1 || intMonth == 3 || intMonth == 5 || intMonth == 7 || intMonth == 8 || intMonth == 10 || intMonth == 12) && (intday > 31 || intday < 1)) {
return false;
}
if ((intMonth == 4 || intMonth == 6 || intMonth == 9 || intMonth == 11) && (intday > 30 || intday < 1)) {
return false;
}
if (intMonth == 2) {
if (intday < 1) {
return false;
}
if (LeapYear(intYear) == true) {
if (intday > 29) {
return false;
}
}
else {
if (intday > 28) {
return false;
}
}
}
if (strDatestyle == "US") {
datefield.value = strMonthArray[intMonth-1] + " " + intday+" " + strYear;
}
else {
datefield.value = intday + " " + strMonthArray[intMonth-1] + " " + strYear;
}
return true;
}
function LeapYear(intYear) {
if (intYear % 100 == 0) {
if (intYear % 400 == 0) { return true; }
}
else {
if ((intYear % 4) == 0) { return true; }
}
return false;
}function checkdata(){
var strdate=document.form1.strdate;
if (chkdate(strdate)==false){
alert("The date is Invalid!")
document.form1.strdate.select();
document.form1.strdate.focus();
return false;
}
}
//-->
</script>
</HEAD>
<BODY onload="javascript:test()">
<form name="form1" method="post" action="">
<table width="100%" border="0">
<tr>
<td width="45%">
<div align="right">Please input the Date:</div>
</td>
<td width="55%">
<input type="text" name="strdate">
</td>
</tr>
<tr>
<td colspan="2">
<div align="center"> </div>
</td>
</tr>
<tr>
<td colspan="2">
<div align="center">
<input type="button" name="Button" value="Submit" onClick="javascript:checkdata()" style="cursor:hand">
</div>
</td>
</tr>
</table>
</form>
</BODY>
</HTML>