<!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完整代碼實現
<!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>
③ 鎴戝湪PHP涓璁$畻鍑轟簡涓涓鍊掕℃椂鐨勫,鎬庢牱鐢↗S姣忛殧1縐掑埛鏂板嚭鏉ュ埌緗戦〉涓
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>JS瀹炵幇鍊掕℃椂(鏃躲佸垎錛岀)</title>
<script language="javascript" type="text/javascript">
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(2016,6,5,'divdown1');
}, interval);
</script>
</head>
<body>
<div id="divdown1"></div>
</body>
</html>
緇欎綘鎻愪緵涓鎬濊礬
④ js鍊掕℃椂錛屼負浠涔堜笉鑷鍔ㄥ埛鏂版椂闂達紵璇烽珮鎵嬫寚鏁
<html>
<head>
<metacharset="UTF-8"/>
<title>JS鐨凾AB鍒囨崲</title>
<scripttype="text/javascript">
functioncountdown()
{
varend=newDate(2014,10,29,3);
varnow=newDate();
varm=Math.round((end-now)/1000);
varday=parseInt(m/24/3600);
varhours=parseInt((m%(3600*24))/3600);
varminutes=parseInt((m%3600)/60);
varseconds=m%60;
if(m<0)
{
document.getElementById("clock").innerHTML='0';
return;
}
document.getElementById("clock").innerHTML="紱誨紑濮嬭繕鍓"+day+"澶"+hours+"灝忔椂"+minutes+"鍒嗛挓"+seconds
+"縐";
setTimeout('countdown()',1000);
}
window.onload=function()
{
countdown();
}
</script>
</head>
<body>
<spanid="clock"></span>
</body>
</html>
⑤ js倒計時代碼
<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怎麼寫2秒後再刷新當前頁面
設置定時2秒後執行刷新。
<script type="text/javascript">
setTimeout(function(){//使用setTimeout()方法設定定時2000毫秒
window.location.reload();/內/頁面容刷新
},2000);
</script>
(6)js倒計時刷新擴展閱讀:
html代碼和JS代碼的區別
一、基礎不同
1、JS代碼:基於原型編程、多範式的動態腳本語言,並且支持面向對象、命令式和聲明式(如函數式編程)風格。
2、html代碼:是由HTML命令組成的描述性文本,HTML命令可以說明文字、圖形、動畫、聲音、表格、鏈接等。
二、用處不同
1、JS代碼:用於Web應用開發,常用來為網頁添加各式各樣的動態功能,為用戶提供更流暢美觀的瀏覽效果。
2、html代碼:結構包括頭部(Head)、主體(Body)兩大部分,其中頭部描述瀏覽器所需的信息,而主體則包含所要說明的具體內容。
⑦ 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 怎麼定時刷新指定頁面
將<metahttp-equiv=\\\"refresh\\\"content=\\\"20\\\">添加到head中,content=\\\"20\\\"指每隔20秒刷新一次頁面.
也可以用下面版的JS控制
<scriptlanguage=\\\"JavaScript\\\">
functionmyrefresh(){
window.location.reload();
}
setTimeout(\\\'myrefresh()\\\',1000);//指定權1秒刷新一次
</script>
或者是
functionrefresh()
{
window.location.href=\\\"當前頁面URL\\\";
setTimeout(\\\"refresh()\\\",10000);
}
⑨ 高分跪求求一個循環倒計時的JS代碼,網頁上用的。
<span id="span_dt_dt"></span>
<script language=javascript>
var daytemp=3//新增加變數
function show_date_time(){
window.setTimeout("show_date_time()", 1000);
BirthDay=new Date("02/26/2012");//改成你的計時日期
today=new Date();
timeold=(BirthDay.getTime()-today.getTime());
sectimeold=timeold/1000
secondsold=Math.floor(sectimeold);
msPerDay=24*60*60*1000
e_daysold=timeold/msPerDay
daysold=Math.floor(e_daysold);
e_hrsold=(e_daysold-daysold)*24;
hrsold=Math.floor(e_hrsold);
if (hrsold < 10){
hrsold = "0"+hrsold;
}
e_minsold=(e_hrsold-hrsold)*60;
minsold=Math.floor((e_hrsold-hrsold)*60);
if (minsold < 10){
minsold = "0"+minsold;
}
seconds=Math.floor((e_minsold-minsold)*60);
if (seconds < 10){
seconds = "0"+seconds;
}
//以下為增加代碼:希望你測試通過,然後給分
if(daysold>=0)
{
document.getElementById("span_dt_dt").innerHTML=daysold+"<b>D</b>"+hrsold+"<b>H</b>"+minsold+"<b>M</b>"+seconds+"<b>S</b>";
}
else
{
if(daysold+daytemp>=0)
{
document.getElementById("span_dt_dt").innerHTML=(daysold+daytemp)+"<b>D</b>"+hrsold+"<b>H</b>"+minsold+"<b>M</b>"+seconds+"<b>S</b>";
}
else
{
daytemp=daytemp+3;
}
}
}
show_date_time();
</script>