JavaScriptは簡単なタイマーを実現します.
1945 ワード
コードは以下の通りです
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title> </title>
</head>
<script type="text/javascript">
var num=0;
var i;
function startCount(){
document.getElementById('count').value=num;
num=num+1;
i=setTimeout("startCount()",1000);
}
function stopCount(){
clearTimeout(i);
}
</script>
</head>
<body>
<form>
<input type="text" id="count" />
<input type="button" value="Start" onClick="startCount()" />
<input type="button" value="Stop" onClick="stopCount()" />
</form>
</body>
</html>
JavaScriptが現在の日付を取得しました. フォーマット:[年月日] 時:分:秒 日曜日 <html>
<head>
<title></title>
<script language="javascript">
function getCurDate()
{
var d = new Date();
var week;
switch (d.getDay()){
case 1: week=" "; break;
case 2: week=" "; break;
case 3: week=" "; break;
case 4: week=" "; break;
case 5: week=" "; break;
case 6: week=" "; break;
default: week=" ";
}
var years = d.getYear();
var month = add_zero(d.getMonth()+1);
var days = add_zero(d.getDate());
var hours = add_zero(d.getHours());
var minutes = add_zero(d.getMinutes());
var seconds=add_zero(d.getSeconds());
var ndate = years+" "+month+" "+days+" "+hours+":"+minutes+":"+seconds+" "+week;
divT.innerHTML= ndate;
}
function add_zero(temp)
{
if(temp<10) return "0"+temp;
else return temp;
}
setInterval("getCurDate()",100);
</script>
</head>
<body>
<div id="divT"></div>
</body>
</html>