この記事では、JavaScriptタイマーの完全な実装方法について説明します。参照のためにそれを共有してください。特定の実装方法は次のとおりです。
コードを次のようにコピーします。<
<html>
<head>
<meta http-equiv = "content-type" content = "text/html; charset = utf-8">
<title>タイマー</title>
<script type = "text/javascript">
varタイマー= null;
function begin(){
var date = new Date();
var current_time = date.getTullyear() + ' - ' + date.getMonth() + ' - ' + date.getDate() + '';
current_time + = date.gethours() + ':' + date.getMinutes() + ':' + date.getSeconds();
document.getElementById( 'current_time')。value = current_time;
Timer = setimeout( 'begin()'、1000);
}
function end(){
ClearTimeout(タイマー); //タイマーオブジェクトをクリアします
}
</script>
</head>
<body>
<入力型= "text" name = "current_time" id = "current_time"/> <入力タイプ= "ボタン" value = "start" onclick = "begin();">
<入力型= "button" value = "end" onclick = "end();"/> <br/>
</body>
</html>
この記事がみんなのJavaScriptプログラミングに役立つことを願っています。