点击“开始”,计时开始。
点击“停止”,计时停止。
点击“清除”,清除已计算的时间。
特点:计时的数据用HTML5的localStorage存储。
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Survey</title>
<script type="text/javascript" src="http://apps.bdimg.com/libs/jquery/1.9.1/jquery.min.js"></script>
<style type="text/css">
h3,label {
font-size:11px;
}
button{
cursor:pointer;
}
</style>
</head>
<script type="text/javascript">
var trun;
var pbut;
function startVote(){
//localStorage
if (localStorage.pagecount)
{
localStorage.pagecount=Number(localStorage.pagecount) + 1;
}else{
localStorage.pagecount=1;
}
document.getElementById("th1ID").innerHTML = "运行了: " + localStorage.pagecount + " 次。";
//
//这里可以干更多的事儿...
//
trun = setTimeout("startVote()",1000); //设置运行间隔时间,默认每1秒。
document.getElementById("startPost").setAttribute('disabled','true');
}
function stopVote(){
clearTimeout(trun);
document.getElementById("startPost").removeAttribute('disabled');
}
function clearVote(){
localStorage.pagecount = 0;
document.getElementById("th1ID").innerHTML = "运行了: 0 次。";
//$('#th1ID').html("运行了: 0 次。");
}
</script>
<body>
<h2 id='th1ID'>点击‘开始’按钮开始计时...</h2>
<button id='startPost' οnclick="startVote()"> 开始 </button>
<button id='stopPost' οnclick="stopVote()"> 停止 </button>
<button id='clearPost' οnclick="clearVote()"> 清除 </button>
</body>
</html>