<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style type="text/css">
#test {
50px;
height: 50px;
text-align: center;
line-height: 50px;
font-size: 50px;
border: 1px solid black;
color: red;
}
</style>
</head>
<body>
<div id="test">
</div>
</body>
<script src="js/jquery-1.12.3.min.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
var continuousDay = 0;
var dateArray = [20161210, 20161211, 20161212, 20161219,20161220,20161221];
var date = new Date();
var today = date.getFullYear().toString() + (date.getMonth() + 1).toString() + date.getDate().toString();
var yestoday=parseInt(today)-1;
//alert(yestoday)
//var today=date.getMonth()+1
//alert(today);
// var date = new Date();
// var today = date.getFullYear().toString() + (date.getMonth() + 1).toString() + date.getDate().toString();
//判断是否连续签到
for(var m = dateArray.length - 1; m > 0; m--) {
//如果是今天
if (dateArray[m] == parseInt(today)) {
//alert("今天")
if(dateArray[m] - dateArray[m - 1] == 1){
continuousDay += 1;
$("#test").html(continuousDay+1);
}else{
break;
}
//如果是昨天
} else if(dateArray[m] == yestoday){
//alert("昨天")
if(dateArray[m] - dateArray[m - 1] == 1){
continuousDay += 1;
$("#test").html(continuousDay+1);
}else{
$("#test").html(continuousDay+1);
}
//既不是昨天也不是今天
}else{
break;
alert("既不是昨天也不是今天")
$("#test").html("0");
}
}
</script>
</html>