87,997
社区成员




<div>Timer:<span id="timer" stat="off">0.00</span></div>
<button id="b1">开始</button>
<button id="b2">暂停</button>
<button id="b3">记忆</button>
<textarea id='rec' style="display:block;width:100%;height:300px;"></textarea>
<script>
function addSec(){
if ($('#timer').attr('stat')=='on')
{
// 为了避免浮点计算造成的问题,这里使用正则强制转换成整型计算,然后再用正则生成结果
var n = parseInt($('#timer').text().replace(/\./g,''))+1;
var t = ('000'+n).replace(/(\d{2})$/g,'.$1').replace(/^0+(?=\.)/g,'0').replace(/^0+(?=\d)/g,'')
$('#timer').text(t);
}else{
clearInterval(window.timer1);
}
}
function start(){
window.timer1 = setInterval(function(){addSec()},10);
}
$(document).ready(function(){
$('#b1').click(function(){
if ($('#timer').attr('stat')=='off')
{
$('#timer').attr('stat','on');
start();
$(this).html('停止')
}else{
$('#timer').attr('stat','off');
clearInterval(window.timer1);
$('#timer').text('0.00');
$(this).html('开始')
$('#rec').val('');
}
});
$('#b2').click(function(){
if ($('#timer').attr('stat')=='off')
{
$('#timer').attr('stat','on');
start();
$(this).html('暂停')
}else{
$('#timer').attr('stat','off');
clearInterval(window.timer1);
$(this).html('继续')
}
});
$('#b3').click(function(){
$('#rec').val($('#rec').val()+'\n'+$('#timer').text())
});
});
</script>
var m=60;
var one = 0;
function fun(){
var val = document.getElementById("get_identifying");
val.setAttribute("disabled", true);
val.value="重新发送(" + m + ")";
m--;
if(m<0){
val.removeAttribute("disabled");
val.value="获取验证码";
m = 60;
one++;
clearTimeout("fun()");
}else{
setTimeout("fun()",1000);
}
}
这个是倒计时60秒的。one就是次数的累加