<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="jquery-2.1.1.min.js"></script>
<title>倒计时</title>
<style type="text/css">
*{
margin: 0;
padding: 0;
}
#tele {
margin: 200px auto;
width: 500px;
height: 180px;
background-color: #c40000;
text-align: center;
font-size: 30px;
box-sizing: border-box;
display: -webkit-box;
-webkit-box-pack: center;
-webkit-box-align: center;
}
input{
width: 30px;
}
</style>
</head>
<body onload="init(1,13,'month');init(1995,2019,'year');init(1,32,'day');">
<div >
<select id="year">
<option>年</option>
</select>年
<select id="month">
<option>月</option>
</select>月
<select id="day">
<option>日</option>
</select>日
<input type="text" name="" id="hours" placeholder="时">:
<input type="text" name="" id="minutes" placeholder="分">:
<input type="text" name="" id="seconds" placeholder="秒">
<input type="button" name="" id="length" value="时间间隔" style="width: 60px" onclick="time();">
</div>
<div id="tele"></div>
<script type="text/javascript">
function init(a,b,c){
var nothing = "";
for(var i = a; i < b; i++){
nothing = nothing +"<option value = '"+i+"' id = attr'"+"''"+i+"'>"+i+"</option>";
}
document.getElementById(c).innerHTML = nothing;
}
var old = new Date();
function time(){
last = old.setFullYear($("#year").val(),($("#month").val()-1),$("#day").val());
laster = old.setHours($("#hours").val(),$("#minutes").val(),$("#seconds").val());
setInterval(edge,1000);
}
function edge(){
var now = new Date();
var lasttime = now.getTime() - old.getTime();
var lastseconds = parseInt(lasttime / 1000); //秒
var minutes = 0;
var hours = 0;
var day = 0;
var month = 0;
var year = 0;
if (lastseconds > 60) {
minutes = parseInt(lastseconds / 60);
lastseconds = parseInt(lastseconds % 60);
if (minutes > 60) {
hours = parseInt(minutes / 60);
minutes = parseInt(minutes % 60);
if (hours > 24) {
day = parseInt(hours / 24);
hours = parseInt(hours % 24);
if (day > 30) {
month = parseInt(day / 30);
day = parseInt(day % 30);
if (month >12) {
year = parseInt(month / 12);
month = parseInt(month % 12);
}
}
}
}
}
document.getElementById('tele').innerHTML =year +"年" + ""+ month + "个月" + "" + day+ "天" + "" + hours+ "时" + ":" + minutes+ "分" + ":" + lastseconds + "秒";
}
</script>
</body>
</html>
简单的特定时间段内的计时代码,关于select下拉框滚动条的长度的写法
最新推荐文章于 2023-03-13 14:37:09 发布