time=0.000s
<!DOCTYPE html>
<html lang="ja">
<head>
<script type="text/javascript">
var st;
function timer(){
if(document.getElementById("bt").innerHTML=="start"){
document.getElementById("bt").innerHTML="stop";
st=new Date();
hyouji();
}else{
clearTimeout(repeat);
document.getElementById("bt").innerHTML="start";
}
}
function hyouji(){
et=+new Date();
atai.innerHTML ="time="+eval(et-st)/1000+"s";
repeat = setTimeout(hyouji,10);
}
</script>
<title>timer</title>
</head>
<body>
<button onclick="timer()">push</button>
<p id="atai">time=0.000s</p>
</body>
</html>
|