<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>

解决方案 »

  1.   

    <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 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>
      

  2.   

    hjx398(娱乐主角),感谢你的回复. 但你的程序似乎有错误.如果今天是31号,客户定下个月10号,你的程序光拿31和10做对比是不行的. 
    另外能不能再加一个功能:预定时间不能在当前时间前?再次感谢,搞定后一定给分!
      

  3.   

    <script>
    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>
      

  4.   

    搞定了,多谢 hjx398(娱乐主角)接分啦,哥们!!