您的位置:首页 > 其它

秒杀的倒计时按钮实现

2017-04-28 15:00 441 查看
ps:只有按钮 没有秒杀 还在做

一个小小的按钮 花了我一个下午的时间 自己水平还是太次啊

直接贴代码html>

html lang="en">

head>

meta charset="UTF-8">

</title>

script>

head>

body>

br>

input type="button" id="btn" value="秒杀" disabled="true"/>

body>

script type="text/javascript">

$(function(){

var stringTime = "2017-04-27 19:44:00";

var timestamp2 = Date.parse(new Date(stringTime));

timestamp2 = timestamp2 / 1000; //获取到的 格式日期 的时间戳

var myDate = new Date();

var timestamp = myDate.getTime()/1000; //当前时间戳 获取的时间戳为毫秒 需除1000

timestamp = timestamp.toFixed();

//过了某时间 直接不可点

var stringTime3 = "2017-04-27 20:02:00";

var timestamp4 = Date.parse(new Date(stringTime3));

timestamp4 = timestamp4 / 1000; //获取到的 格式日期 的时间戳

if(timestamp>timestamp4){

alert('活动已结束');

return;

}

if(timestamp>timestamp2 && timestamp<timestamp4){

$("#btn").val("秒杀").removeAttr("disabled");

return;

}

var count = timestamp2 - timestamp;

var countdown = setInterval(CountDown, 1000);

function CountDown() {

$("#btn").val("离活动开始还有" + count + "秒");

if (count == 0) {

$("#btn").val("秒杀").removeAttr("disabled");

clearInterval(countdown);

}

count--;

}

});

script>
http://www.cnblogs.com/zyjfire/articles/6775383.html 食用
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐