js实现日期加1

访客7年前javaScript2010

直接附代码

方法1:

<html>
<head>
   <script>
      function getLocalTime(addNum){//参数为加几天
  var today,ms,thatDay, y, m, d,endDate;
  today = new Date().getTime();
  ms = today + addNum*24*60*60*1000;
  thatDay = new Date(ms);
  y = thatDay.getFullYear();
  m = thatDay.getMonth()+1;
  d = thatDay.getDate();
  endDate = y+"-"+m+"-"+d;
  alert(endDate);
  //return endDate;
}
   </script>
</head>
<body>
 <input type='text'  id='a'  onclick="getLocalTime('1')"/>
</body>
<html>

方法2:

<html>
<head>
   <script>
      function getLocalTime(addNum){//参数为加几天
      var d2=document.getElementById("aa").value;    
      var arys= new Array();
      arys=d2.split('-');
       //得到日期类型
      var myDate = new Date(arys[0],arys[1],arys[2]); 
      myDate=myDate.valueOf();         
      myDate=myDate +addNum * 24 * 60 * 60 * 1000;
      myDate = new Date(myDate);
      alert(myDate.getFullYear() + "-" + (myDate.getMonth()) + "-" + myDate.getDate() );
}
   </script>
</head>
<body>
 <input type='text'  id='aa' value='2017-7-5' onclick="getLocalTime('1')"/>
</body>
<html>
标签: js萨瓦迪卡

相关文章

jquery获取下拉列表选中的文本值

                 &nb...

js/jquery 日历控件及实例下载

js/jquery 日历控件及实例下载

实现日历控件效果:页面:<link href="${base}/resource/${profile.path}/css/lhgcalendar.css" rel="...

js限制input只能输入数字、英文、汉字

 1.只能输入数字和英文的:  <input onkeyup="value=value.replace(/[\W]/g,'') "...

js实现字符串 传参数 作为变量名 并为其赋值(动态变量名)

直接附代码,自己测试<html> <script> //例如:为变量x赋值1 xvalue('x','1');//变量名为:x,值为:1....

api.js去掉class样式

api.js去掉class样式

<div class="aui-list-item-inner aui-list-item-arrow" id="name"></div>...

js控制文本域textarea 剩余可填字符显示

Html部分:<span class="remo"><div>还可以输入<span style="font-family: Georgia;...

评论列表

二次元空间
2017-07-10 15:27:35

文章写的挺不错的,留言支持下,欢迎回访我的网站,你网站挺不错的,能否交换友链。

发表评论    

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。