一个javascript的函数,控制form1.in_dt1的值在上月的26到本月的25日,如何实现?

linuxsun999 2003-06-24 08:34:54
一个javascript的函数,控制form1.in_dt1的值在上月的26到本月的25日,如不是返回false,
函数如下,但不起作用,请问如何解决
<SCRIPT LANGUAGE=javascript>
<!--
function CheckForm(){
var d,d2,d_start,d_end ,m,y
d=new Date();
m=d.getMonth();
y=d.getYear();
if (m==1) {
d_start= new Date(y-1,12,26);
}
else{
d_start=new Date(y,m-1,26);
}
d_end=new Date(y,m,25)
alert(d_start);
alert(d_end);
s=form1.in_dt1 .value
ss=s.split("-")
d2=new Date(ss[0],ss[1]-1,ss[2]);
alert(d2);
if ((d2<=d_start) && (d2>=d_end)){
alert("您选择的时间必须为上月的26到本月的25日!");
return false;
}
}
//-->
</SCRIPT>
...全文
94 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
linuxsun999 2003-06-25
  • 打赏
  • 举报
回复
没人回复自己又考虑了下,原来是把条件写错了。
if ((d2<d_start) || (d2>d_end))
不过还是很感谢 Laone(Laone!
Laone 2003-06-24
  • 打赏
  • 举报
回复
给你一个JS版的DateDiff和DateAdd,你自己参考一下怎么写,功能和vbs的相似
function TimeCom(dateValue){
var newCom = new Date(dateValue);
this.year = newCom.getYear();
this.month = newCom.getMonth()+1;
this.day = newCom.getDate();
this.hour = newCom.getHours();
this.minute = newCom.getMinutes();
this.second = newCom.getSeconds();
this.msecond = newCom.getMilliseconds();
this.week = newCom.getDay();
}

function DateDiff(interval,date1,date2){
var TimeCom1 = new TimeCom(date1);
var TimeCom2 = new TimeCom(date2);
var result;
switch(String(interval).toLowerCase()){
case "y":
case "year":
result = TimeCom1.year-TimeCom2.year;
break;
case "n":
case "month":
result = (TimeCom1.year-TimeCom2.year)*12+(TimeCom1.month-TimeCom2.month);
break;
case "d":
case "day":
result = Math.round((Date.UTC(TimeCom1.year,TimeCom1.month-1,TimeCom1.day)-Date.UTC(TimeCom2.year,TimeCom2.month-1,TimeCom2.day))/(1000*60*60*24));
break;
case "h":
case "hour":
result = Math.round((Date.UTC(TimeCom1.year,TimeCom1.month-1,TimeCom1.day,TimeCom1.hour)-Date.UTC(TimeCom2.year,TimeCom2.month-1,TimeCom2.day,TimeCom2.hour))/(1000*60*60));
break;
case "m":
case "minute":
result = Math.round((Date.UTC(TimeCom1.year,TimeCom1.month-1,TimeCom1.day,TimeCom1.hour,TimeCom1.minute)-Date.UTC(TimeCom2.year,TimeCom2.month-1,TimeCom2.day,TimeCom2.hour,TimeCom2.minute))/(1000*60));
break;
case "s":
case "second":
result = Math.round((Date.UTC(TimeCom1.year,TimeCom1.month-1,TimeCom1.day,TimeCom1.hour,TimeCom1.minute,TimeCom1.second)-Date.UTC(TimeCom2.year,TimeCom2.month-1,TimeCom2.day,TimeCom2.hour,TimeCom2.minute,TimeCom2.second))/1000);
break;
case "ms":
case "msecond":
result = Date.UTC(TimeCom1.year,TimeCom1.month-1,TimeCom1.day,TimeCom1.hour,TimeCom1.minute,TimeCom1.second,TimeCom1.msecond)-Date.UTC(TimeCom2.year,TimeCom2.month-1,TimeCom2.day,TimeCom2.hour,TimeCom2.minute,TimeCom2.second,TimeCom1.msecond);
break;
case "w":
case "week":
result = Math.round((Date.UTC(TimeCom1.year,TimeCom1.month-1,TimeCom1.day)-Date.UTC(TimeCom2.year,TimeCom2.month-1,TimeCom2.day))/(1000*60*60*24)) % 7;
break;
default:
result = "invalid";
}
return(result);
}

function DateAdd(interval, num, dateValue){
var newCom = new TimeCom(dateValue);
switch(String(interval).toLowerCase()){
case "y": case "year": newCom.year += num; break;
case "n": case "month": newCom.month += num; break;
case "d": case "day": newCom.day += num; break;
case "h": case "hour": newCom.hour += num; break;
case "m": case "minute": newCom.minute += num; break;
case "s": case "second": newCom.second += num; break;
case "ms": case "msecond": newCom.msecond += num; break;
case "w": case "week": newCom.day += num*7; break;
default: return("invalid");
}
var now = newCom.year+"/"+newCom.month+"/"+newCom.day+" "+newCom.hour+":"+newCom.minute+":"+newCom.second;
return(new Date(now));
}
linuxsun999 2003-06-24
  • 打赏
  • 举报
回复
没人回答?

28,390

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧