<script type="text/javascript"> var timeout; $(function () { timeout = setInterval(showsykssj, 1000); }) function showsykssj() { /*顯示剩余考試時間*/ var hour = 12; //結束時間 var minite = 0; var second = 0; var date1 = new Date(1986, 1, 22, hour, minite, second); var date2 = new Date(1986, 1, 22, new Date().getHours(), new Date().getMinutes(), new Date().getSeconds()); var nDiff = date1 - date2; var nHour, nMini, nSecond; nHour = parseInt(nDiff / 3600000); nMini = parseInt(nDiff % 3600000 / 60000); nSecond = parseInt(nDiff % 60000 / 1000); if (nMini == 0 && nSecond == 0) { alert("考試時間到,系統(tǒng)自動交卷。"); clearInterval(timeout); } else { document.getElementById("sykssj").innerHTML = "距離" + hour + "點" + minite + "分" + second + "秒還有:" + nHour + "小時" + nMini + "分" + nSecond + "秒"; } } </script>