js 代码
- //get the date string of today (1985/11/16)
- function getDateString()...{
- var myDate=new Date();
- //get the full year(4 number,1970-????)
- var year=myDate.getFullYear();
- //get the month(0-11,0 is Jan)
- var monthNum=myDate.getMonth();
- var month;
- if(monthNum<9)...{
- month="0"+(monthNum+1);
- }else...{
- month=monthNum+1;
- }
- //get day(1-31)
- var day=myDate.getDate();
- if(day<9)...{
- day="0"+day;
- }
- var today=year+"/"+month+"/"+day
- return today;
- }
js 代码
- //验证文本框不能为空
- function checkNull()...{
- var checkItems=new Array( "date", "timeFrom","timeTo");
- msgArray=...{
- "date":"createTimesheet.date",
- "timeFrom":"createTimesheet.timeFrom",
- "timeTo":"createTimesheet.timeTo"
- };
- for(i in checkItems)...{
- var item=document.getElementById(checkItems[i]);
- var text=item.value;
- if(text==null||text=="")...{
- alert(msgArray[checkItems[i]]);
- return false;
- }
- }
- var temp=document.mainForm.date.value;
- if(temp==null||temp=="")...{
- alert("createTimesheet.date" />");
- return false;
- }
- return true;
- }
java 代码
- //校验2007/11/30 格式的日期,不正确的返回false
- //字符串替换 全局替换“/”chkDate=chkDate.replace(///g,"");
- //全局替换 a换成b chkDate=chkDate.replace(/a/g,"b");
- //替换一个a换成b chkDate=chkDate.replace("a","b");
- function checkSlashYyyymmdd(sDate)...{
- var chkDate=sDate;
- if(chkDate.length !=10)...{
- return false;
- }
- if (chkDate.charAt(4) != "/")...{
- return false;
- }
- if (chkDate.charAt(7) != "/")...{
- return false;
- }
- var yyyy=chkDate.substring(0,4);
- var mm=chkDate.substring(5,7);
- if(isNaN(mm)==true)...{
- return false;
- }
- mm=parseInt(mm);
- var dd=chkDate.substring(8,10);
- var Dt;
- Dt=new Date(yyyy,mm-1,dd);
- if ((Dt.getFullYear()==yyyy) && (Dt.getMonth()+1==mm) && (Dt.getDate()==dd))...{
- return true;
- }
- return false;
- }
本文介绍了一种使用JavaScript获取当前日期格式为YYYY/MM/DD的方法,并实现了一个文本框非空检查的功能,同时提供了一个针对YYYY/MM/DD格式日期的有效性验证函数。


被折叠的 条评论
为什么被折叠?



