js 加载初始化日期

//初始化加载时间
$(function(){ 
var now = new Date();
     
     var year = now.getFullYear();       //年
     var month = now.getMonth() + 1;     //月
     var day = now.getDate();            //日
    
     var clock = year + "-";

     if(month < 10){
    clock += "0";

     }
    clock += month + "-"; 

     
    
     if(day < 10){
    clock += "0";

     }
     clock += day + "";
   
$("#xxx").val(clock); //时间


}); 

版权声明:本文博客原创文章,博客,未经同意,不得转载。

原文地址:https://www.cnblogs.com/yxwkf/p/4632999.html