前端如何设置一天只能点击一次的以及如何去判断第二天0点刷新的一些问题
当需要在前端去判断一天只能点击一次,第二天0点重置的时候,该如何去解决呢? 一、首先你需要获取第二天0点的时间,目前我的方法有两种 1.原生 var time= new Date(); time.setDate(t.getDate() + 1); time.setHours(0); time.setMinutes(0); time.setSeconds(0); console.log(t.getTime()) //第二天0点以毫秒为单位的时间 2.引入moment.js var t = moment().format('x')//当前点击时间 var nextDate = moment().add(1, 'days').hours(0).minutes(0).seconds(0).format('x')//新一天的时间 二、使用localStorage或者cookie去存储一些数据设置过期时间为(第二天0点的时间 - 第一次点击的时间) 这里我用到的是localStorage,由于localStorage原型上自带的属性方法里没有设置过期时间,需要自己封装两个方法用来存和取 Storage.prototype.setExpire = (key, value, expire) => { //设置存 let obj = { data: value, //要存的信息 time: