<html>
<body>
离半夜12点还有<spanid="hour"></span>小时版<spanid="min"></span>分
</body>
<script>
functioncountdown(){
vartoday=newDate();
权varh=today.getHours();
varm=today.getMinutes();
h=23-h;
m=59-m;
m=checkTime(m)
document.getElementById("hour").innerHTML=h;
document.getElementById("min").innerHTML=m;
}
functioncheckTime(i){
if(i<10)i="0"+i;
returni;
}
setInterval("countdown()",50);
</script>
<html>
⑵ 制作倒计时有开始和暂停按钮用js完整代码实现
<!doctypehtml>
<htmllang="en">
<head>
<metacharset="UTF-8">
<title>Document</title>
</head>
<body>
<inputplaceholder="请输入时间"id="inp">
<buttononclick="go()">start</button><buttononclick="stop()">stop</button><buttonid="jixu"onclick="jixu()"style="display:none;">continue</button>
<divid="result"></div>
<script>
vartime,
div=document.getElementById('result'),
stopState=false;
functiongo(){
time=document.getElementById('inp').value;
timeout();
}
functiontimeout(){
if(time==''){
alert('请输入时间')
return;
}
setTimeout(function(){
time--;
div.innerText=time;
if(time!==0&&!stopState){
timeout();
}
},1000);
}
functionjixu(){
time=Number(document.getElementById('result').innerText);
document.getElementById('jixu').style.display='none';
stopState=false;
timeout();
}
functionstop(){
document.getElementById('jixu').style.display='';
stopState=true;
}
</script>
</body>
</html>
⑶ 如何用js显示3分钟倒计时并输出指定数字
functiontimeshow(){
vartime=3;//s
varstart=window.setInterval(function(){
time=time-1;
console.log(time);
document.getElementById('show').innerHTML='计时开始,'+time+'秒后跳转!';
if(time==0){
window.clearInterval(start);
document.getElementById('show').innerHTML='计时结束';
}
},1000);
}
⑷ 求一个倒计时js代码,非常简单的
逻辑如下:
1、先判断两个时间的时间差,当然如果得到的时间是13位时间戳的话你需要转化一下
2、判断时间够一天显示天数,够一小时显示小时数
相关代码:
//获取时间,时间戳转换,不是则不转
varmydate1=newDate(parseInt(time1.replace("/Date(","").replace(")/","")));
varmydate2=newDate(parseInt(time2.replace("/Date(","").replace(")/","")));
//获取剩余秒数
vartimerc=dateDiff(mydate,'2015/05/1910:00:00')/1000;
functiondateDiff(date1,date2){
vardt1=newDate(Date.parse(date1));
vardt2=newDate(Date.parse(date2));
try{
returnMath.round((dt2.getTime()-dt1.getTime()));
}
catch(e){
returne.message;
}
}
//循环调用倒计时
functionadd(){//加时函数
--timerc;//时间变量自减1
varday=parseInt(timerc/86400);
varhour=parseInt((timerc%86400)/3600);
varmin=parseInt((timerc%3600)/60);
varsec=Number(parseInt(timerc%60/10)).toString()+Number(parseInt((timerc%10))).toString();
if(day>0){//如果不到5分钟
$("#day").html(day+'天');//写入天数
$("#hour").html(hour+'时');//写入小时数
$("#min").html(min+'分');//写入分钟数
$("#sec").html(sec+'秒');//写入秒数(两位)
}
elseif(hour>0){
$("#hour").html(hour+'时');//写入小时数
$("#min").html(min+'分');//写入分钟数
$("#sec").html(sec+'秒');//写入秒数(两位)
}
elseif(min>0){
$("#min").html(min+'分');//写入分钟数
$("#sec").html(sec+'秒');//写入秒数(两位)
}
elseif(sec!='00'){
$("#sec").html(sec+'秒');//写入秒数(两位)
}
else{
tiao(activity);returntrue;//时间到0调用函数
}
setTimeout("add()",1000);//设置1000毫秒以后执行一次本函数
};
望采纳!
⑸ 如何用javascript实现一小时倒计时
js代码:fun.js
var timmerID = null;
function time() {
var time = document.getElementById("now");
var left = document.getElementById("left");
var t = time.value.split(":");
var hour = parseInt(t[0]);
var min = parseInt(t[1]);
min=min+1;
if(min==60){
hour=hour+1;
min=0;
if(hour==24){
hour=0;
}
}
time.value=hour+":"+min;
left.value = left.value-1;
if(left.value==0){
mystop();
alert("时间已到!");
}
}
function mystart() {
var left = document.getElementById("left");
left.value="40";
timmerID = window.setInterval("time()", 1000*60);
}
function mystop() {
window.clearInterval(timmerID);
}
html页面:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>time.html</title>
<script type="text/javascript" src="fun.js"></script>
</head>
<body>
时间起点:<input type="text" name="now" id="now" value="0:0"/><input type="button" value="开始" onclick="mystart();"><br>
剩余时间:<input type="text" name="left" id="left" value="40" disabled="disabled"/>分钟<br>
</body>
</html>
补充:这个javascript放在一个文件叫fun.js,在html页面中要引用此文件,如:<script type="text/javascript" src="fun.js"></script> ,注意不要把路径弄错了,src后面的路径按照实际的来,如果两个文件在一个目录下,就是如上这样引用,当然也可以直接把全部的js内容放在html文件的头部,如:<script type="text/javascript">
<!--javascript代码-->
</script>
⑹ JS 倒计时实现代码(时、分,秒)
JS实现倒计时(时、分,秒)
var
interval
=
1000;
function
ShowCountDown(year,month,day,divname)
{
var
now
=
new
Date();
var
endDate
=
new
Date(year,
month-1,
day);
var
leftTime=endDate.getTime()-now.getTime();
var
leftsecond
=
parseInt(leftTime/1000);
//var
day1=parseInt(leftsecond/(24*60*60*6));
var
day1=Math.floor(leftsecond/(60*60*24));
var
hour=Math.floor((leftsecond-day1*24*60*60)/3600);
var
minute=Math.floor((leftsecond-day1*24*60*60-hour*3600)/60);
var
second=Math.floor(leftsecond-day1*24*60*60-hour*3600-minute*60);
var
cc
=
document.getElementById(divname);
cc.innerHTML
=
"脚本之家提示距离"+year+"年"+month+"月"+day+"日还有:"+day1+"天"+hour+"小时"+minute+"分"+second+"秒";
}
window.setInterval(function(){ShowCountDown(2010,4,20,'divdown1');},
interval);
[Ctrl+A
全选
注:如需引入外部Js需刷新才能执行]
⑺ JS 5秒倒计时的代码怎么写时间要实时显示在屏幕上的。
<!DOCTYPEhtml>
<htmllang="en">
<head>
<metahttp-equiv="Content-Type"content="text/html;charset=utf-8"/>
<title>js实现倒计时60秒的简单代码(推荐)</title>
<scripttype="text/javascript"src="js/jquery.js"></script>
</head>
<body>
<inputtype="button"id="btn"value="免费获取验证码"onclick="settime(this)"/>
<scripttype="text/javascript">
varcountdown=60;
functionsettime(val){
if(countdown==0){
val.removeAttribute("disabled");
val.value="免费获取验证码";
countdown=5;
}else{
val.setAttribute("disabled",true);
val.value="重新发送("+countdown+")";
countdown--;
setTimeout(function(){
settime(val)
},1000)
}
}
</script>
</body>
</html>
⑻ JS实现 倒计时程序,需求如下:当时间小于10分钟时,
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
</head>
<body>
<input type="button" id="btn" value="免费获取验证码" />
<script type="text/javascript">
var wait=5; //第一次时间设置时间(秒为单位)
function time(o) {
if (wait == 0) {
o.removeAttribute("disabled");
o.value="免费获取验证码";
wait = 5; //重新的时间设置时间(秒为单位)
} else {
o.setAttribute("disabled", true);
o.value="重新发送(" + wait + ")";
wait--;
setTimeout(function() {
time(o)
},1000) ////1000就是1秒钟提醒一次
if(wait<2){ //少于2秒钟时,每次提醒一次提醒一次
alert('1'); //alert 提示框提醒
}
}
}
document.getElementById("btn").onclick=function(){time(this);}
</script>
</body>
</html>
注:alert 提示框提醒,不按确定时间会停止的!
⑼ js瀹炵幇璺濈2023骞5鏈1鏃ヨ繕鏈夊氬皯澶,灏忔椂,鍒,绉掔殑瀹炴椂鍊掕℃椂鏁堟灉锛
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>鍊掕℃椂</title>
</head>
<body>
<div id="countdown"></div>
<script>
// 瀹氫箟鍊掕℃椂鎴姝㈡椂闂
const endTime = new Date('2023-05-01 00:00:00').getTime();
// 姣忕掓洿鏂颁竴娆″掕℃椂
const countdown = setInterval(function() {
// 鑾峰彇褰撳墠鏃堕棿鎴
const nowTime = new Date().getTime();
// 璁$畻鏃堕棿宸锛堟绉掞級
const timeDiff = endTime - nowTime;
// 璁$畻鍓╀綑澶╂暟銆佸皬鏃舵暟銆佸垎閽熸暟銆佺掓暟
const days = Math.floor(timeDiff / (1000 * 60 * 60 * 24));
const hours = Math.floor((timeDiff % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
const minutes = Math.floor((timeDiff % (1000 * 60 * 60)) / (1000 * 60));
const seconds = Math.floor((timeDiff % (1000 * 60)) / 1000);
// 灏嗗掕℃椂鏄剧ず鍦ㄩ〉闈涓
document.getElementById('countdown').innerHTML = '璺濈2023骞5鏈1鏃ヨ繕鏈夛細' + days + '澶 ' + hours + '灏忔椂 ' + minutes + '鍒 ' + seconds + '绉';
// 缁撴潫鍊掕℃椂
if (timeDiff < 0) {
clearInterval(countdown);
document.getElementById('countdown').innerHTML = '鍊掕℃椂宸茬粨鏉燂紒';
}
}, 1000);
</script>
</body>
</html>