javascript空白页面出现

时间:2014-10-25 00:20:34

标签: javascript html button charts

当我在互联网上加载此页面时,屏幕显示为空白,我已经写出了其他java脚本页面的问题,所以我想知道,有没有我缺少的代码或什么?

<html>
  <head>
    <script tpye=text/javascript> 
      function Dateg (date1, date2) { 
        var a = 1000 * 60 * 60 * 24; 
        var difeq = date2.getTime() - date1.getTime(); 
        var dif = Math.round(difeq / a); 
        return days;
      } 
    </script>
  </head>
  <body>
    <script type=text/javascript>
      var day1 = new Date(2014, 10, 24);
      var day2 = new Date(2014, 10, 27);
      var dif = dateDif(day1, day2);
      alert("there are " + dif + " days between " + day1.toDateString() =+ " and " + day2.toDateString()); 
    </script>
  </body>
</html>

1 个答案:

答案 0 :(得分:1)

您发布的代码存在一些问题,请参阅评论

<html>
<head>
    <script type="text/javascript"> //type not tpye and probably best practice to wrap the text/javascript in "" like most other tag attribute values
        function Dateg(date1, date2) {
            var a = 1000 * 60 * 60 * 24; 
            var difeq = date2.getTime() - date1.getTime();
            var dif = Math.round(difeq / a); 
            return dif; //return dif not days, days is not defined
    }
    </script>
</head>

<body>
    <script type="text/javascript"> //same thing with the quote wrapped around text/javascript
        var day1 = new Date(2014, 10, 24);
        var day2 = new Date(2014, 10, 27);
        var dif = Dateg(day1, day2); //Dateg is the name of your function not dateDif
        alert("there are " + dif + " days between " + day1.toDateString() +" and " + day2.toDateString()); //you need to remove to equal sign after day1.toDateString()
    </script>
</body>

</html>

控制台是你的朋友!