我有一個自己運行正常的秒錶代碼。我試圖在用戶衝入時啓動並顯示它,以便計算時間並在用戶衝出時停止。我想用這些數據然後插入數據庫。我會怎麼做呢?如何在數據插入數據庫後啓動秒錶?
<?php if($timedata['is_clocked_in'] === 'Yes'):?>
<h5 style="text-transform: uppercase" class="alert alert-info col-md-4">You Are Clocked In : (time count) </h5>
<?php elseif($timedata['is_clocked_in'] === 'No'):?>
<button><i class="fa fa-plus" aria-hidden="true"></i> Punch In Now</button>
<?php endif;?>
標記
<h1><time>00:00:00</time></h1>
<button id="start">start</button>
<button id="stop">stop</button>
<button id="clear">clear</button>
腳本
var h1 = document.getElementsByTagName('h1')[0],
start = document.getElementById('start'),
stop = document.getElementById('stop'),
clear = document.getElementById('clear'),
seconds = 0, minutes = 0, hours = 0,
t;
function add() {
seconds++;
if (seconds >= 60) {
seconds = 0;
minutes++;
if (minutes >= 60) {
minutes = 0;
hours++;
}
}
h1.textContent = (hours ? (hours > 9 ? hours : "0" + hours) : "00") + ":" + (minutes ? (minutes > 9 ? minutes : "0" + minutes) : "00") + ":" + (seconds > 9 ? seconds : "0" + seconds);
timer();
}
function timer() {
t = setTimeout(add, 1000);
}
timer();
/* Start button */
start.onclick = timer;
/* Stop button */
stop.onclick = function() {
clearTimeout(t);
}
/* Clear button */
clear.onclick = function() {
h1.textContent = "00:00:00";
seconds = 0; minutes = 0; hours = 0;
}
感謝這一點,但是PHP並不是一個真正的'現場'解決方案......再加上PHP的時間從來就不是本地的......我需要設置時區以使其正確,這將需要我爲此編寫完整的類即時建設國際。 –
你只需要時間而不是絕對時間,所以你不需要本地時間。 –
好的。你介意分享一些東西來展示你在說什麼嗎? –