jquery 如何在JS数据库中增加数据

jvidinwx  于 2024-01-07  发布在  jQuery
关注(0)|答案(1)|浏览(260)

为什么我不能通过点击+来增加日期?

  1. var dayLength = 1000*3600*24;
  2. var current = new Date();
  3. console.log(current);
  4. $('button').on('click', function(){
  5. var a = new Date((new Date()).valueOf() + dayLength);
  6. console.log(a);
  7. });

个字符

py49o6xq

py49o6xq1#

dayLength添加到当前日期new Date()。您应该将其添加到current变量。

  1. var dayLength = 1000*3600*24;
  2. var current = new Date();
  3. console.log(current);
  4. $('button').on('click', function(){
  5. current = new Date(current.getTime() + dayLength);
  6. console.log(current);
  7. });

个字符
请注意,我还将valueOf更改为getTime,因为对于docs,通常不会在用户代码中调用valueOf

相关问题