JavaScript實現(xiàn)簡單日期特效
JavaScript之日期特效的具體代碼,供大家參考,具體內(nèi)容如下
直接上代碼:
<!DOCTYPE html><html lang='en'><head> <meta charset='UTF-8'> <title>Title</title> <style type='text/css'>*{ padding: 0; margin: 0;}#date{ width: 450px; height: 300px; background-color: darkorange; border-radius: 10px; margin: 100px auto;}#nowDate{ width: 450px; height: 60px; line-height: 60px; text-align: center; color: #fff; font-size: 26px;}#day{ width: 200px; height: 200px; line-height: 200px; background-color: orchid; margin: 0 auto; text-align: center;} </style></head><body> <div id='date'><p id='nowDate'></p><p id='day'></p> </div> <script type='text/javascript'>// 獲取標(biāo)簽var nowDate = document.getElementById('nowDate');var day = document.getElementById('day');// 用定時器 更新時間的變化setInterval(nowNumTime,1000);nowNumTime();function nowNumTime(){ var now = new Date(); var hour = now.getHours(); var minute = now.getMinutes(); var second = now.getSeconds(); var temp = ’’ + (hour>12 ? hour-12:hour); var year = now.getFullYear(); var month = now.getMonth(); var d = now.getDate(); var week = now.getDay(); console.log(week); //索引 var weeks = ['星期天','星期一','星期二','星期三','星期四','星期五','星期六']; // console.log(temp); if (hour ===0){temp = ’12’; } temp = temp + (minute <10 ? ’:0’:':'+minute); temp = temp + (second <10 ? ’:0’:':'+second); temp = temp + (hour>=12 ? ’ P.M.’:’ A.M.’); temp = `${year}年${month}月$is2tiay日 ${temp}${weeks[week]}`; // console.log(temp); nowDate.innerHTML = temp;} </script></body></html>
實現(xiàn)效果圖:
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. el-input無法輸入的問題和表單驗證失敗問題解決2. vue跳轉(zhuǎn)頁面常用的幾種方法匯總3. react腳手架配置代理的實現(xiàn)4. JavaScript中顏色模型的基礎(chǔ)知識與應(yīng)用詳解5. 前端html+css實現(xiàn)動態(tài)生日快樂代碼6. JavaScript快速實現(xiàn)一個顏色選擇器7. CSS3實例分享之多重背景的實現(xiàn)(Multiple backgrounds)8. 不要在HTML中濫用div9. Jquery使用原生AJAX方法請求數(shù)據(jù)10. React實現(xiàn)一個倒計時hook組件實戰(zhàn)示例
