简单的特定时间段内的计时代码,关于select下拉框滚动条的长度的写法

<!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的函数注意一下,当时出不来。select要在页面初始化的时候显示,所以一开始就要初始化。另外关于select的下拉框的大小,可以直接用<select size ="2"> 确定滚动条的长度
然后关于时间的函数,直接取两个时间的时间戳,取差,求各级的时间,方法比较烦,重复代码较多,但是简单明了。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值