首页 > 代码库 > js时钟显示

js时钟显示

<script type="text/javascript">	onload=function(){		start();		clock = window.setInterval(‘start()‘,1000);		btn = document.getElementById(‘btn‘);		btn.addEventListener(‘click‘,timeOut);		btnTxt = btn.childNodes[0];	}		function start(){		var date = new Date();				var s = date.getSeconds();		var i = date.getMinutes();		var h = date.getHours();		var d = date.getDate();		var m = date.getMonth()+1;		var y = date.getFullYear();                //date.toLocaleDateString()——格式化本地日期                //date.toLocaletimeString()——格式化本地时间		var week = [‘星期天‘,‘星期一‘,‘星期二‘,‘星期三‘,‘星期四‘,‘星期五‘,‘星期六‘];		week = week[date.getDay()];		var str = y+‘-‘+m+‘-‘+d+‘  ‘+h+‘:‘+i+‘:‘+s+‘  ‘+week;				var dv = document.getElementById(‘dv‘);		var txt = document.createTextNode(str);		dv.replaceChild(txt,dv.childNodes[0]);	}		function timeOut(){		var start = document.createTextNode(‘开始‘);				if(btn.firstChild.nodeValue=http://www.mamicode.com/=‘暂停‘){>

<div id="dv">这里显示时钟</div>
<button id="btn">暂停</button>