不知道你需要什么样的注释:
CheckDateChar(checkStr)判断是否是除"0123456789-";以外的字符CheckDate(dateText) 判断是否‘1977-01-01’或‘77-01-01’
CheckDateChar(checkStr)判断是否是除"0123456789-";以外的字符CheckDate(dateText) 判断是否‘1977-01-01’或‘77-01-01’
调试欢乐多
{
var strYear;
var strMonth;
var strDate;var intYear = 0;
var intMonth = 0;
var intDate = 0;var intToday = 0;
var intInputDay;var strInputDate = dateText.value;
var inputDate;
var today = new Date();var firstDelimiter = 0;
var secondeDelimiter = 0;
//1、上面定义的这些变量都是做什么的??
firstDelimiter = strInputDate.indexOf("-", 0);
strYear = strInputDate.substring(0, firstDelimiter);
//这两个语句是什么意思?
secondeDelimiter = strInputDate.indexOf("-", firstDelimiter + 1);
strMonth = strInputDate.substring(firstDelimiter + 1, secondeDelimiter);
strDate = strInputDate.substring(secondeDelimiter + 1, strInputDate.length);//这句是什么意思?intYear = parseInt(strYear, 10);
//month should - 1;
intMonth = parseInt(strMonth, 10) - 1;
intDate = parseInt(strDate, 10);
if( intYear <= 99 )
{
inputDate = new Date(1900 + intYear, intMonth, intDate);
}//这句是什么意思 ?
else
inputDate = new Date(intYear, intMonth, intDate);if( inputDate.getMonth() == intMonth && inputDate.getDate() == intDate )
{
//alert("Year:" + inputDate.getYear() + "Month:" + (inputDate.getMonth() + 1) + "date:" +
inputDate.getDate());
if( intYear <= 99 )
{
strYear = "19" + strYear;
dateText.value = strYear + "-" + strMonth + "-" + strDate;
}
} //这几句是什么 意思?
else
{
//alert("invalid date!");
return 1;
}return 0;
}
var flag = CheckDate(document.RG_frm.birth);
if( document.RG_frm.birth.value.length<8 || !CheckDateChar(document.RG_frm.birth.value) || flag
== 1)
{
window.alert("\"出生日期\"输入格式不正确,应如‘1977-01-01’或‘77-01-01’。");
document.RG_frm.birth.focus();
return(false);
}
多谢指教!!
{
var strYear;//变量字符型的年
var strMonth;//变量字符型的月
var strDate;//变量字符型的日var intYear = 0;//变量数字型的年
var intMonth = 0;//变量数字型的月
var intDate = 0;//变量数字型的日期var intToday = 0;//定义当然日期
var intInputDay;//定义输入的日期var strInputDate = dateText.value;//定义一个输入日期的变更并把所检查的元素的值付给这个变量
var inputDate;
var today = new Date();//得到系统的日期 date()启用基本存储器并取得日期和时间var firstDelimiter = 0;//定义两个变量,第一个分隔符所在的位置,如2004-06-07中的第一个分隔符
var secondeDelimiter = 0;//第二分隔所在的位置,如2004-06-07中的第二个分隔符
//1、上面定义的这些变量都是做什么的??
firstDelimiter = strInputDate.indexOf("-", 0);//返回 String 对象内第一次出现子字符串的字符位置.如如2004-06-07中的第一个分隔符06前面的那个分隔符的位置.strYear = strInputDate.substring(0, firstDelimiter);//通过取子串得到年份,如2004-06-07中的第一个分隔符前面的2004代表的年份
//这两个语句是什么意思?
secondeDelimiter = strInputDate.indexOf("-", firstDelimiter + 1);//查找从第一个分隔符开始的第一个分隔字符以"-"就是上面2004-06-07中的07前面的那个分隔符
strMonth = strInputDate.substring(firstDelimiter + 1, secondeDelimiter);//通过取子串把如2004-06-07中的第一个分隔符到第二个分隔符之间的字符付给月变量,如06付给变量月
strDate = strInputDate.substring(secondeDelimiter + 1, strInputDate.length);//通过取第二个子串开始的字符,到结束为此为天变量的值,如2004-06-07中的07这日期变量intYear = parseInt(strYear, 10);//返回由字符串转换得到的整数。把strYear的值转换为整数值,付给intYear变量
//month should - 1;
intMonth = parseInt(strMonth, 10) - 1;//返回由字符串转换得到的整数。把strMonth的值转换为整数值,付给intMonth变量,因为整数的月份是从0-11,所以要减一个1
intDate = parseInt(strDate, 10);//得到整数型的日期变量(天)
if( intYear <= 99 )
{
inputDate = new Date(1900 + intYear, intMonth, intDate);//如果时间格式是如下的话:04-05-04,就要进行转换成1904-05-04这种格式,所以用date相加来实现
//并将其转换成日期时间格式
}//这句是什么意思 ?
else
inputDate = new Date(intYear, intMonth, intDate);//如果是其它的话,则直接转换就可以了
if( inputDate.getMonth() == intMonth && inputDate.getDate() == intDate )
{
//alert("Year:" + inputDate.getYear() + "Month:" + (inputDate.getMonth() + 1) + "date:" +
inputDate.getDate();
if( intYear <= 99 )
{
strYear = "19" + strYear;//对78这样的年进行组合,组合成1978年
dateText.value = strYear + "-" + strMonth + "-" + strDate;//对年月日进行组合组合成1978-10-18这样日期格式,以便处理
}
} //这几句是什么 意思?
else
{
//alert("invalid date!");
return 1;
}return 0;
}
var flag = CheckDate(document.RG_frm.birth);
if( document.RG_frm.birth.value.length<8 || !CheckDateChar(document.RG_frm.birth.value) || flag
== 1)
{
window.alert("\"出生日期\"输入格式不正确,应如‘1977-01-01’或‘77-01-01’。");
document.RG_frm.birth.focus();
return(false);
}
多谢指教!!
看看我自己的检查日期的方法:
<script>
function checknumeric(el)
{
//如果含有非字母数字 返回 true
var text1="1234567890";
for(i=0;i<=el.length-1;i++)
{
char1=el.charAt(i);
index=text1.indexOf(char1);
if(index==-1){
return true;//非法
}
//没有
}
return false;
}
function check(){
if(checknumeric(document.form1.month.value)||(document.form1.month.value>12 || document.form1.month.value<1))
{
alert("the birthday's month is not legal");
document.form1.month.focus();
return false;
}
if(checknumeric(document.form1.year.value)||(document.form1.year.value >2005 || document.form1.year.value < 1900))
{
alert("the birthday's year is not legal");
document.form1.year.focus();
return false;
}
}然在在存取时对这个进行组合
stryearmont=year+month
</script>
<form name=form1 onsubmit=return check()>
<input type=text name="year" value="">年<input type=text name="month" value="">月
</form>