一、Js代碼
function getTime(){ str = "當前系統時間:" var p = document.getElementById("sy_time"); time = new Date(); year = time.getFullYear(); month = time.getMonth() + 1; day = time.getDate(); hour = time.getHours(); minutes = time.getMinutes(); seconds = time.getSeconds(); str = str + year +"-"+ month +"-"+ day + " " +hour+":"+minutes+":"+seconds; p.innerText = str; setTimeout(getTime,1000); } window.onload = function(){ getTime(); } 二、前端代碼
<!-- 頁面調用代碼 --><p id = "sy_time"></p>
以上所述是小編給大家介紹的JavaScript實現實時更新系統時間的實例代碼,希望對大家有所幫助,如果大家有任何疑問歡迎給我留言,小編會及時回復大家的,在此也非常感謝大家對武林網網站的支持!
新聞熱點
疑難解答