<script>
function $()
{
var date=new Date();
var day=date.getDate();
newDate=document.getElementsByName("form1")[0].Tim.value;
if(newDate.split("-")[2]-day>5)
{
alert("预定的时间不能大于5天!");
return;
}
}
</script>
<form action="" method="post" name="form1" onsubmit="return $()">
<input name="Tim" type="text" value="2007-06-29"/>
<input name="submit" type="submit" value="提交" />
</form>
function $()
{
var date=new Date();
var day=date.getDate();
newDate=document.getElementsByName("form1")[0].Tim.value;
if(newDate.split("-")[2]-day>5)
{
alert("预定的时间不能大于5天!");
return;
}
}
</script>
<form action="" method="post" name="form1" onsubmit="return $()">
<input name="Tim" type="text" value="2007-06-29"/>
<input name="submit" type="submit" value="提交" />
</form>
解决方案 »
- IE8中img动态修改src时,内存不能释放的问题
- jwplayer 调用seek方法后 getPosition()不同步问题
- 用JS或jquery获取当前页面ID后两位为“_R”的checkbox
- Iframe操作父页面跨域跳转,IE提示无权限
- 后台输出长字符串到前台js变量接受报错
- JQuery beforeSend用法
- js代码兼容;求JQuery插件
- 一个基础的xml问题 不知道错哪里 请大虾们指教!!!!
- 简单问题,如何设置文本框中的光标在文本后面
- 一个关于select里面用了onChange事件的奇怪问题。急切ing....
- 内部js 和外部js 还有不同的运行权限??
- 如何用 js 让 <tr> 不可用? 在线等!
function $()
{
var date=new Date();
var day=date.getDate();
newDate=document.getElementsByName("form1")[0].Tim.value;
if(newDate.split("-")[2]-day>5)
{
alert("预定的时间不能大于5天!");
return false;
}
else
{
return true;
}
}
</script>
<form action="" method="post" name="form1" onsubmit="return $()">
<input name="Tim" type="text" value="2007-06-29"/>
<input name="submit" type="submit" value="提交" />
</form>
另外能不能再加一个功能:预定时间不能在当前时间前?再次感谢,搞定后一定给分!
function $()
{
var date=new Date();//时间
var day=date.getDate();//日
var month=date.getMonth()+1//月
var year=date.getFullYear()//年
s1 =year+"-"+month+"-"+day
s2 = document.getElementsByName("form1")[0].Tim.value;
if(DateDiff(s1,s2)<0)//是否允许预定今天的在这里修改,1为不允许
{
alert("预定的时间不能小于今天!")
return false;
}
if(DateDiff(s1,s2)>5)
{
alert("预定的时间不能大于5天!")
return false;
}
}
//计算天数差的函数,通用
function DateDiff(sDate1,sDate2)
{ //sDate1和sDate2是2002-12-18格式
var aDate,oDate1,oDate2,iDays
aDate=sDate1.split("-")
oDate1=new Date(aDate[1]+'-'+aDate[2]+'-'+aDate[0]) //转换为12-18-2002格式
aDate=sDate2.split("-")
oDate2=new Date(aDate[1]+'-'+aDate[2]+'-'+aDate[0])
iDays = parseInt(Math.abs(oDate1 -oDate2)/1000/60/60/24) //把相差的毫秒数转换为天数
if(oDate1<oDate2)
{
return iDays;
}
else
{
return -iDays ;
}
}
</script>
<form action="" method="post" name="form1" onsubmit="return $()">
<input name="Tim" type="text" value="2007-06-29"/>
<input name="submit" type="submit" value="提交" />
</form>