js带闹铃功能的倒计时代码

网络编程 发布日期:2024/10/3 浏览次数:1

正在浏览:js带闹铃功能的倒计时代码

Js倒计时代码,带闹铃功能,自定义闹钟倒计时功能,点击开始按钮,即可开始倒数,代码不是太复杂,新手应该能看懂,代码分享给大家。
效果图:

js带闹铃功能的倒计时代码

源码:

<html> 
<head> 
<title>Js倒计时,闹铃功能</title> 
<script language="javascript"> 
function $(id){ 
 return document.getElementById(id); 
} 
function down(){ 
 $("second").value-=1; 
 
 if($("second").value==0&&$("minutes").value==0&&$("hours").value==0) 
 { 
 window.alert("干正事了!!!"); 
 clearInterval(timeout); 
  
 } 
 
 
 if($("second").value==-1) 
 { 
 $("second").value=59; 
 $("minutes").value-=1; 
 } 
 if($("minutes").value==-1) 
 { 
 $("minutes").value=59; 
 $("hours").value-=1; 
 } 
} 
var timeout; 
function begin(){ 
 timeout=setInterval("down()",1000); 
} 
function stop(){ 
 clearInterval(timeout); 
} 
var dt=new Date(); 
function setclock() 
{ 
 var hours=$("clock_hours").value-dt.getHours(); 
 var minutes=$("clock_minutes").value-dt.getMinutes(); 
 if(minutes<0) 
 { 
 if(hours<0) 
 { 
 $("minutes").value=60-Math.abs(minutes); 
 $("hours").value=24-Math.abs(hours); 
 } 
 else if(hours==0) 
 { 
 $("minutes").value=60-Math.abs(minutes); 
 $("hours").value=Math.abs(hours); 
 } 
 else 
 { 
 $("minutes").value=60-Math.abs(minutes); 
 $("hours").value=Math.abs(hours)-1; 
 } 
 } 
 else if(minutes==0) 
 { 
 if(hours<0) 
 { 
 $("minutes").value=Math.abs(minutes); 
 $("hours").value=24-Math.abs(hours); 
 } 
 else if(hours==0) 
 { 
 $("minutes").value=Math.abs(minutes); 
 $("hours").value=Math.abs(hours)+24; 
 } 
 else 
 { 
 $("minutes").value=Math.abs(minutes); 
 $("hours").value=Math.abs(hours); 
 } 
 } 
 else 
 { 
 if(hours<0) 
 { 
 $("minutes").value=60-Math.abs(minutes); 
 $("hours").value=24-Math.abs(hours); 
 } 
 else if(hours==0) 
 { 
 $("minutes").value=Math.abs(minutes); 
 $("hours").value=Math.abs(hours); 
 } 
 else 
 { 
 $("minutes").value=Math.abs(minutes); 
 $("hours").value=Math.abs(hours); 
 } 
 } 
} 
function reset() 
{ 
 var time=document.getElementsByName("time"); 
 for(i=0;i<time.length;i++) 
 { 
 time[i].value=0; 
 } 
} 
</script> 
</head> 
<body> 
距闹铃响起的时间还有:<input type="text" id="hours" style="width:20px" value="0" name="time" /> 
:<input type="text" id="minutes" value="0" style="width:20px" name="time"/>: 
<input type="text" id="second" value="0" style="width:20px" name="time"/><br/> 
<input type="text" id="clock_hours" value="0" style="width:20px" name="time"/>时: 
<input type="text" id="clock_minutes" value="0" style="width:20px" name="time"/>分<br/> 
<input type="button" value="设置闹钟" onclick="setclock()" /> 
<input type="button" value="重置" onclick="reset()" /><br/> 
<input type="button" value="开始" onclick="begin()"> 
<input type="button" value="停止" onclick="stop()"> 
</body> 
</html> 

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。

高通与谷歌联手!首款骁龙PC优化Chrome浏览器发布
高通和谷歌日前宣布,推出首次面向搭载骁龙的Windows PC的优化版Chrome浏览器。
在对骁龙X Elite参考设计的初步测试中,全新的Chrome浏览器在Speedometer 2.1基准测试中实现了显著的性能提升。
预计在2024年年中之前,搭载骁龙X Elite计算平台的PC将面世。该浏览器的提前问世,有助于骁龙PC问世就获得满血表现。
谷歌高级副总裁Hiroshi Lockheimer表示,此次与高通的合作将有助于确保Chrome用户在当前ARM兼容的PC上获得最佳的浏览体验。