例1 一些免费获取验证码效果
代码如下 | 复制代码 |
<input type="button" id="btn" value="免费获取验证码" /> <script type="text/javascript"> var wait=60; function time(o) { if (wait == 0) { o.removeAttribute("disabled"); o.value="免费获取验证码"; wait = 60; } else { o.setAttribute("disabled", true); o.value="重新发送(" + wait + ")"; wait--; setTimeout(function() { time(o) }, 1000) } } document.getElementById("btn").onclick=function(){time(this);} </script> |
例2
代码如下 | 复制代码 |
常见的注册看协义的效果 <script language="javascript"> <!-- var wait_time = 8; //设置秒数(单位秒) var secs_time = 0; for(var i=1;i<=wait_time;i++) { window.setTimeout("sTimer("+i+")",i*1000); } function sTimer(num) { if(num==wait_time) { document.getElementById("reg_btn").value=" 同意注册 "; document.getElementById("reg_btn").disabled=false; } else { secs_time=wait_time-num; document.getElementById("reg_btn").value="请先阅读服务条款 ("+secs_time+")"; } } //--> </script> html代码
<div style="width:350px; text-align:center;"> |
活动即将开始的读秒效果
代码如下 | 复制代码 |
//刷新DIV代码 function fresh(){ ++times; //var begintime=new Date(); var begintime=new Date(Date.parse(beginTime)); var endtime=new Date(Date.parse(endTime)); var leftsecond=parseInt((endtime.getTime()-begintime.getTime())/1000); leftsecond-=times; d=parseInt(leftsecond/3600/24); h=parseInt((leftsecond/3600)%24); m=parseInt((leftsecond/60)%60); s=parseInt(leftsecond%60); rushPurchaseStr='还有'+d+'天'+h+'小时'+m+'分'+s+'秒 开始抢购!' ; $("#rushPurchase").html(rushPurchaseStr); if(leftsecond<=0){ rushPurchaseStr='抢购正在进行中...'; $("#rushPurchase").html(rushPurchaseStr); clearInterval(sh); } } |