码迷,mamicode.com
首页 > Web开发 > 详细

页面加载JS事件

时间:2016-05-19 19:05:53      阅读:148      评论:0      收藏:0      [点我收藏+]

标签:

window.onload = function showDate() {
var now = new Date();
var year = now.getFullYear();
var month = (now.getMonth() + 1 > 9) ? now.getMonth() + 1 : "0" + (now.getMonth() + 1);//当月
var date = (now.getDate() > 9) ? now.getDate() : "0" + now.getDate();
var lastmonth = (now.getMonth() > 9) ? now.getMonth() : "0" + now.getMonth();//上个月
//var lastmonthdate = (now.getDate() - 30 > 9) ? now.getDate() - 30 : "0" + now.getDate() - 30;//今天 -30
if (document.getElementById("ID") != null) {
document.getElementById("ID").value = year + "-" + lastmonth + "-" + date;
}
if (document.getElementById("ID") != null) {
document.getElementById("ID").value = year + "-" + month + "-" + date;
}
}

页面加载JS事件

标签:

原文地址:http://www.cnblogs.com/ss196/p/5509530.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!