热门关键字:
jquery > jquery教程 > javascript > 网友Adam‘分享原创JS时间类

网友Adam‘分享原创JS时间类

1531
作者:管理员
发布时间:2012/10/25 15:17:14
评论数:0
转载请自觉注明原文:http://www.jq-school.com/Show.aspx?id=164
window.onload = function (){
   var oDoc = document,
   oNewDiv = oDoc.createElement("div"),
   GetDate = function(oDate){
      this.y = oDate.getFullYear();
      this.mo = oDate.getMonth()+1;
      this.d = oDate.getDate();
      this.h = oDate.getHours();
      this.m = oDate.getMinutes();
      this.s = oDate.getSeconds(); 
   };
   GetDate.prototype = {
      showTime : function(){
         var arr = [];
         arr[0] = this.y + "年";
         arr[1] = this.mo + "月";
         arr[2] = this.d + "日";
         arr[3] = this.h + "时";
         arr[4] = this.m + "分";
         arr[5] = this.s + "秒";
         return arr.join("");
      },
      fnPrint: function(dom){
         dom.innerHTML = "当前时间: " + this.showTime();
      }
   };
   var oNow = new GetDate(new Date());
   oNewDiv.id = "showTime";
   oNewDiv.innerHTML = document.body.appendChild(oNewDiv);
   var oDiv = oDoc.getElementById("showTime");
   oNow.fnPrint(oDiv);
   setInterval(function(){
      var oNow2 = new GetDate(new Date());
      oNow2.fnPrint(oDiv);
   },1000);
}




如果您觉得本文的内容对您的学习有所帮助:支付鼓励



关键字:js时间类 原创
友荐云推荐