!在线等!急!!!关于javascript中日期合法性的判定! 我的form是用<select>输入的 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 我想把<select>中的输入都提出来,再用if (isNaN(Date.parse("MM/DD/YYYY"))){}不知可不可行? <html><head><script language="JavaScript"><!--var objReport=null;var objYear=null;var objMonth=null;var objDate=null;/* *页面初始化 */function init(name){ var dlts = document.getElementsByName(name); objReport=dlts[0]; objYear=dlts[1]; objMonth=dlts[2]; objDate=dlts[3]; objReport.attachEvent("onchange",RptChg); objYear.attachEvent("onchange",YearChg); objMonth.attachEvent("onchange",MonthChg); var date = new Date(); var curYear=date.getYear(); var curMonth=date.getMonth()+1; var curDate=date.getDate(); if(objYear == null || objMonth == null || objDate == null ){ alert("Can't find object!"); return false; } var str=""; optAdd(objReport,"年报"); optAdd(objReport,"月报"); optAdd(objReport,"日报"); initDltValue(objYear,1990,2050); initDltValue(objMonth,1,12); initDltValue(objDate,1,CalDays(curYear,curMonth)); objReport.value="日报"; objYear.value=curYear; objMonth.value=curMonth; objDate.value=curDate;} /* *添加select的option值 */function initDltValue(obj,min,max){ for(var i=min;i<=max;i++) optAdd(obj,i);}/* *当报表类型改变的时候 */function RptChg(){ switch(objReport.options[objReport.selectedIndex].value){ case '年报': setDisabled(false,true,true); break; case '月报': setDisabled(false,false,true); break; case '日报': setDisabled(false,false,false); break; }}/* *当年份改变的时候 */function YearChg(){ var dateVal=objDate.value; objDate.innerHTML=""; initDltValue(objDate,1,CalDays(parseInt(objYear.value),parseInt(objMonth.value))); objDate.value=dateVal; if(objDate.selectedIndex==-1) objDate.selectedIndex=0;}/* *当月份改变的时候 */function MonthChg(){ objDate.innerHTML=""; initDltValue(objDate,1,CalDays(parseInt(objYear.value),parseInt(objMonth.value)));}/* *设置对象的disabled属性 */function setDisabled(a,b,c){ objYear.disabled=a; objMonth.disabled=b; objDate.disabled=c;}/* *为select对象添加option */function optAdd(obj,val){ var newOpt=document.createElement("option"); obj.add(newOpt); newOpt.value=val; newOpt.text=val;}/* *根据年月计算天数 */function CalDays(year,mon){ var date= new Date(year,mon,0); return date.getDate();}//--></script></head><body onLoad="init('dltDate');init('dltDate1');"><table cellpadding=0 cellspacing=0 border=0 width=400> <tr> <td width="25%"><select name="dltDate" style="width:100%"></select></td> <td width="25%"><select name="dltDate" style="width:100%"></select></td> <td width="25%"><select name="dltDate" style="width:100%"></select></td> <td width="25%"><select name="dltDate" style="width:100%"></select></td> </tr> <tr> <td width="25%"><select name="dltDate1" style="width:100%"></select></td> <td width="25%"><select name="dltDate1" style="width:100%"></select></td> <td width="25%"><select name="dltDate1" style="width:100%"></select></td> <td width="25%"><select name="dltDate1" style="width:100%"></select></td> </tr></table></body></html>这样生成的日期不会错 谢谢zhaoxiaoyang(梅雪香@深圳)啊!不过有没有其他简便的方法啊!~~ 有,用日期控件梅花雪日期控件我也写了一个关于日期的常见操作http://community.csdn.net//Expert/TopicView2.asp?id=4360247&datebasetype=nowjs FAQ贴http://community.csdn.net//Expert/TopicView2.asp?id=4356360&datebasetype=nowDHTML手册,js手册,dom手册下载http://community.csdn.net//Expert/TopicView2.asp?id=4356325&datebasetype=now /*日期三级下拉菜单 (附件2)使用方法:new DateSelectGroup(slYear, slMonth, slDay)或new DateSelectGroup(slYear, slMonth, slDay, year, month, day)前三个参数是下拉菜单对象,为必选;后三个参数可选,为初始化日期。注意year参数必须要在DateSelectGroup.MaxYear与DateSelectGroup.MinYear之间(见代码)本下拉菜单可以自动改变每个月对应的天数。该类可以多次使用,只要声明一个实例,把参数传进去就不用管它了,兼容IE5.01/6 Firefox*/function DateSelectGroup(slYear, slMonth, slDay, year, month, day){ this.slYear = slYear; this.slMonth = slMonth; this.slDay = slDay; this.DataBind = function(year, month, day) { year = year > DateSelectGroup.MaxYear ? DateSelectGroup.MaxYear : year < DateSelectGroup.MinYear ? DateSelectGroup.MinYear : year; month = month > 12 ? 12 : month < 1 ? 1 : month; day = day > DateSelectGroup.GetDaysInMonth(year, month) ? DateSelectGroup.GetDaysInMonth(year, month) : day < 1 ? 1 : day; DateSelectGroup.BindYear(this); DateSelectGroup.BindMonth(this); this.slYear.selectedIndex = DateSelectGroup.MaxYear - year; this.slMonth.selectedIndex = month - 1; DateSelectGroup.BindDay(this); this.slDay.selectedIndex = day - 1; } this.slYear.Group = this; this.slMonth.Group = this; this.slYear.onchange = function() { DateSelectGroup.BindDay(this.Group); } this.slMonth.onchange = function() { DateSelectGroup.BindDay(this.Group); } if(arguments.length == 6) this.DataBind(year, month, day); else { DateSelectGroup.BindYear(this); DateSelectGroup.BindMonth(this); DateSelectGroup.BindDay(this); }}DateSelectGroup.GetDaysInMonth = function(year, month){ var d = new Date(year, month, 0); return d.getDate();}DateSelectGroup.MaxYear = (new Date()).getFullYear();DateSelectGroup.MinYear = 1949;DateSelectGroup.BindYear = function(group){ for(var i = this.MaxYear; i >= this.MinYear; i--) { var op = window.document.createElement("OPTION"); op.value = i; op.innerHTML = i; group.slYear.appendChild(op); }}DateSelectGroup.BindMonth = function(group){ for(var i = 1; i < 13; i++) { var op = window.document.createElement("OPTION"); op.value = i; op.innerHTML = i; group.slMonth.appendChild(op); }}DateSelectGroup.BindDay = function(group){ var days = this.GetDaysInMonth(parseInt(group.slYear.value), parseInt(group.slMonth.value)); if(days != group.slDay.options.length) { days++; group.slDay.innerHTML = ""; for(var i = 1; i < days; i++) { var op = window.document.createElement("OPTION"); op.value = i; op.innerHTML = i; group.slDay.appendChild(op); } }}关于日期的常见操作http://community.csdn.net//Expert/TopicView2.asp?id=4360247&datebasetype=nowjs FAQ贴http://community.csdn.net//Expert/TopicView2.asp?id=4356360&datebasetype=nowDHTML手册,js手册,dom手册下载http://community.csdn.net//Expert/TopicView2.asp?id=4356325&datebasetype=now 求高手1个多选框问题 怎么禁用超链接 如何计算首屏时间 不知道flex builder发到哪个版块关于环境配置的问题 javascript关灯效果 用js获取特殊ID值 求一个正则表达式,谢谢 各位大哥帮帮忙! 如何屏蔽掉enter键? 菜鸟勿进 如何用javascript检验是否输入的是浮点数 求助怎么样在前台截取value中的字段?
<head>
<script language="JavaScript">
<!--
var objReport=null;
var objYear=null;
var objMonth=null;
var objDate=null;
/*
*页面初始化
*/
function init(name){
var dlts = document.getElementsByName(name);
objReport=dlts[0];
objYear=dlts[1];
objMonth=dlts[2];
objDate=dlts[3];
objReport.attachEvent("onchange",RptChg);
objYear.attachEvent("onchange",YearChg);
objMonth.attachEvent("onchange",MonthChg);
var date = new Date();
var curYear=date.getYear();
var curMonth=date.getMonth()+1;
var curDate=date.getDate();
if(objYear == null || objMonth == null || objDate == null ){
alert("Can't find object!");
return false;
}
var str="";
optAdd(objReport,"年报");
optAdd(objReport,"月报");
optAdd(objReport,"日报");
initDltValue(objYear,1990,2050);
initDltValue(objMonth,1,12);
initDltValue(objDate,1,CalDays(curYear,curMonth));
objReport.value="日报";
objYear.value=curYear;
objMonth.value=curMonth;
objDate.value=curDate;}
/*
*添加select的option值
*/
function initDltValue(obj,min,max){
for(var i=min;i<=max;i++)
optAdd(obj,i);
}
/*
*当报表类型改变的时候
*/
function RptChg(){
switch(objReport.options[objReport.selectedIndex].value){
case '年报':
setDisabled(false,true,true); break;
case '月报':
setDisabled(false,false,true); break;
case '日报':
setDisabled(false,false,false); break;
}
}
/*
*当年份改变的时候
*/
function YearChg(){
var dateVal=objDate.value;
objDate.innerHTML="";
initDltValue(objDate,1,CalDays(parseInt(objYear.value),parseInt(objMonth.value)));
objDate.value=dateVal;
if(objDate.selectedIndex==-1) objDate.selectedIndex=0;
}
/*
*当月份改变的时候
*/
function MonthChg(){
objDate.innerHTML="";
initDltValue(objDate,1,CalDays(parseInt(objYear.value),parseInt(objMonth.value)));
}
/*
*设置对象的disabled属性
*/
function setDisabled(a,b,c){
objYear.disabled=a;
objMonth.disabled=b;
objDate.disabled=c;
}
/*
*为select对象添加option
*/
function optAdd(obj,val){
var newOpt=document.createElement("option");
obj.add(newOpt);
newOpt.value=val;
newOpt.text=val;
}
/*
*根据年月计算天数
*/
function CalDays(year,mon){
var date= new Date(year,mon,0);
return date.getDate();}
//-->
</script>
</head>
<body onLoad="init('dltDate');init('dltDate1');">
<table cellpadding=0 cellspacing=0 border=0 width=400>
<tr>
<td width="25%"><select name="dltDate" style="width:100%"></select></td>
<td width="25%"><select name="dltDate" style="width:100%"></select></td>
<td width="25%"><select name="dltDate" style="width:100%"></select></td>
<td width="25%"><select name="dltDate" style="width:100%"></select></td>
</tr>
<tr>
<td width="25%"><select name="dltDate1" style="width:100%"></select></td>
<td width="25%"><select name="dltDate1" style="width:100%"></select></td>
<td width="25%"><select name="dltDate1" style="width:100%"></select></td>
<td width="25%"><select name="dltDate1" style="width:100%"></select></td>
</tr>
</table>
</body>
</html>
这样生成的日期不会错
不过有没有其他简便的方法啊!~~
我也写了一个关于日期的常见操作
http://community.csdn.net//Expert/TopicView2.asp?id=4360247&datebasetype=now
js FAQ贴
http://community.csdn.net//Expert/TopicView2.asp?id=4356360&datebasetype=now
DHTML手册,js手册,dom手册下载
http://community.csdn.net//Expert/TopicView2.asp?id=4356325&datebasetype=now
日期三级下拉菜单 (附件2)使用方法:new DateSelectGroup(slYear, slMonth, slDay)
或
new DateSelectGroup(slYear, slMonth, slDay, year, month, day)前三个参数是下拉菜单对象,为必选;
后三个参数可选,为初始化日期。注意year参数必须要在DateSelectGroup.MaxYear与DateSelectGroup.MinYear之间(见代码)本下拉菜单可以自动改变每个月对应的天数。该类可以多次使用,只要声明一个实例,把参数传进去就不用管它了,兼容IE5.01/6 Firefox*/function DateSelectGroup(slYear, slMonth, slDay, year, month, day)
{
this.slYear = slYear;
this.slMonth = slMonth;
this.slDay = slDay;
this.DataBind = function(year, month, day)
{
year = year > DateSelectGroup.MaxYear ? DateSelectGroup.MaxYear : year < DateSelectGroup.MinYear ? DateSelectGroup.MinYear : year;
month = month > 12 ? 12 : month < 1 ? 1 : month;
day = day > DateSelectGroup.GetDaysInMonth(year, month) ? DateSelectGroup.GetDaysInMonth(year, month) : day < 1 ? 1 : day;
DateSelectGroup.BindYear(this);
DateSelectGroup.BindMonth(this);
this.slYear.selectedIndex = DateSelectGroup.MaxYear - year;
this.slMonth.selectedIndex = month - 1;
DateSelectGroup.BindDay(this);
this.slDay.selectedIndex = day - 1;
}
this.slYear.Group = this;
this.slMonth.Group = this;
this.slYear.onchange = function()
{
DateSelectGroup.BindDay(this.Group);
}
this.slMonth.onchange = function()
{
DateSelectGroup.BindDay(this.Group);
}
if(arguments.length == 6)
this.DataBind(year, month, day);
else
{
DateSelectGroup.BindYear(this);
DateSelectGroup.BindMonth(this);
DateSelectGroup.BindDay(this);
}
}DateSelectGroup.GetDaysInMonth = function(year, month)
{
var d = new Date(year, month, 0);
return d.getDate();
}DateSelectGroup.MaxYear = (new Date()).getFullYear();DateSelectGroup.MinYear = 1949;DateSelectGroup.BindYear = function(group)
{
for(var i = this.MaxYear; i >= this.MinYear; i--)
{
var op = window.document.createElement("OPTION");
op.value = i;
op.innerHTML = i;
group.slYear.appendChild(op);
}
}DateSelectGroup.BindMonth = function(group)
{
for(var i = 1; i < 13; i++)
{
var op = window.document.createElement("OPTION");
op.value = i;
op.innerHTML = i;
group.slMonth.appendChild(op);
}
}DateSelectGroup.BindDay = function(group)
{
var days = this.GetDaysInMonth(parseInt(group.slYear.value), parseInt(group.slMonth.value));
if(days != group.slDay.options.length)
{
days++;
group.slDay.innerHTML = "";
for(var i = 1; i < days; i++)
{
var op = window.document.createElement("OPTION");
op.value = i;
op.innerHTML = i;
group.slDay.appendChild(op);
}
}
}关于日期的常见操作
http://community.csdn.net//Expert/TopicView2.asp?id=4360247&datebasetype=now
js FAQ贴
http://community.csdn.net//Expert/TopicView2.asp?id=4356360&datebasetype=now
DHTML手册,js手册,dom手册下载
http://community.csdn.net//Expert/TopicView2.asp?id=4356325&datebasetype=now