บทความนี้อธิบายวิธีการใช้งานที่สมบูรณ์ของตัวจับเวลา JavaScript แบ่งปันสำหรับการอ้างอิงของคุณ วิธีการใช้งานเฉพาะมีดังนี้:
คัดลอกรหัสดังนี้: <! Doctype html public "-// w3c // dtd html 4.01 transitional // en" "http://www.w3.org/tr/html4/loose.dtd">>
<html>
<head>
<meta http-equiv = "content-type" content = "text/html; charset = utf-8">
<title> ตัวจับเวลา </title>
<script type = "text/javascript">
ตัวจับเวลา var = null;
ฟังก์ชั่นเริ่มต้น () {
วันที่ var = วันที่ใหม่ ();
var current_time = date.getlyear () + '-' + date.getMonth () + '-' + date.getDate () + '';
current_time + = date.getHours () + ':' + date.getMinutes () + ':' + date.getSeconds ();
document.getElementById ('current_time'). value = current_time;
timer = settimeout ('เริ่มต้น ()', 1,000);
-
ฟังก์ชันสิ้นสุด () {
ClearTimeout (ตัวจับเวลา); // ล้างวัตถุตัวจับเวลา
-
</script>
</head>
<body>
<input type = "text" name = "current_time" id = "current_time"/> <อินพุต type = "button" value = "start" onClick = "เริ่มต้น ();">
<อินพุต type = "button" value = "end" onclick = "end ();"/> <br/>
</body>
</html>
ฉันหวังว่าบทความนี้จะเป็นประโยชน์กับการเขียนโปรแกรม JavaScript ของทุกคน