定时器仅30分钟

Rak*_*tty -2 jquery timer

我想设置一个计时器,例如我的产品在添加到购物车时应该只显示30分钟.我试过了 :-

var d = new Date();

var minute = d.getHours()+30;
Run Code Online (Sandbox Code Playgroud)

另外我想向用户显示剩余时间(倒计时)

我知道这是错的.我想用jQuery做到这一点.我是jquery的新手,请帮助我

提前致谢.

wf9*_*m75 8

是的,这有点正确,但我想向用户显示剩余的时间,即倒计时应该开始.如何做到这一点

好的,这个怎么样:

var countdown = 30 * 60 * 1000;
var timerId = setInterval(function(){
  countdown -= 1000;
  var min = Math.floor(countdown / (60 * 1000));
  //var sec = Math.floor(countdown - (min * 60 * 1000));  // wrong
  var sec = Math.floor((countdown - (min * 60 * 1000)) / 1000);  //correct

  if (countdown <= 0) {
     alert("30 min!");
     clearInterval(timerId);
     //doSomething();
  } else {
     $("#countTime").html(min + " : " + sec);
  }

}, 1000); //1000ms. = 1sec.
Run Code Online (Sandbox Code Playgroud)

或者我建议你使用这些插件:http: //www.tripwiremagazine.com/2012/09/jquery-countdown-scripts.html