JS代码如下: var cDate=new Date(); 
  var y=cDate.getFullYear();
  var m=cDate.getMonth()+1;
  var d=cDate.getDate();
  
  var h=cDate.getHours();
  var f=cDate.getMinutes();
  var s=cDate.getSeconds();
  
  var mydate=new Date(y+"-"+m+"-"+d+" "+h+":"+f+":"+s);
  
  var sd="2012-4-27 00:00:00";
  var ed="2012-5-2 00:00:00";
  var startDate=new Date(sd);
  var endDate=new Date(ed);function showAds(){
    if(mydate>startDate && mydate<endDate){
        document.write("**********************");
    }
}不知为何if(mydate>startDate && mydate<endDate)这里没有进入if语句执行document.write这个东西!
请高人指点一下,这样判断不对?
求方法!

解决方案 »

  1.   

    <!DOCTYPE HTML>
    <html>
    <head>
    <meta charset="gb2312" />
    <title></title>
    <style></style>
    </head>
    <body>
    <script>
    var cDate=new Date(); 
      var y=cDate.getFullYear();
      var m=cDate.getMonth()+1;
      var d=cDate.getDate();
      
      var h=cDate.getHours();
      var f=cDate.getMinutes();
      var s=cDate.getSeconds();
      
      var mydate=new Date(y+"/"+m+"/"+d+" "+h+":"+f+":"+s);
      
      var sd="2012/4/27 00:00:00";
      var ed="2012/5/2 00:00:00";
      var startDate=new Date(sd);
      var endDate=new Date(ed);function showAds(){

        if(mydate>startDate && mydate<endDate){
            document.write("**********************");
        }
    }
    showAds()
    </script>
    </body>
    </html>
      

  2.   

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title></title>
    </head>
    <body>
    <script>    var cDate = new Date();
        var y = cDate.getFullYear();
        var m = cDate.getMonth() + 1;
        var d = cDate.getDate();    var h = cDate.getHours();
        var f = cDate.getMinutes();
        var s = cDate.getSeconds();    var mydate = new Date(y + "-" + m + "-" + d + " " + h + ":" + f + ":" + s);    var sd = "2012-4-27 00:00:00";
        var ed = "2012-5-2 00:00:00";
        var startDate = new Date(sd);
        var endDate = new Date(ed);    function showAds() {
            if (mydate > startDate && mydate < endDate) {
                document.write("**********************");
            }
            else {
                alert('aa');
            }
        }
        showAds();
    </script>
    </body>
    </html>一是方法没调用所以不执行了。。二是条件不符合当然不执行了