abstract:【1】js改變css樣式:document.getElementById().style.屬性名="屬性值"。【2】改變元素的屬性值: 1. document.getElementById("id名").屬性名稱 ="屬性值"。 &nb
【1】js改變css樣式:document.getElementById().style.屬性名="屬性值"。
【2】改變元素的屬性值:
1. document.getElementById("id名").屬性名稱 ="屬性值"。
2. document.getElementByClassName("class名").屬性名稱 ="屬性值"。
3. document.getElementByTagName("標簽名").屬性名稱 ="屬性值"。
【3】獲取日期:
Date();獲取當前時間
getFullYear();年
getMonth();月
getDate();日
getHours();時
getMinutes();分
getSeconds();秒
getDay();星期
運行案例:
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>獲取時間</title> <style> .box{ width:800px; height:120px; position: absolute; top:50%; left:50%; margin-top: -60px; margin-left:-400px; text-align: center; } input{ width: 720px; height: 50px; margin-bottom: 10px; border-radius: 6px; border:none; padding:0 10px; } .but{ width:740px; height: 50px; margin-bottom: 10px; font-size: 18px; border-radius: 6px; border:none; background-color: #00a5e0; color: #fff; } button:hover{background-color:#fff;color:#00a5e0;} </style> <script> function myclick(){ var myday=new Date() var month=new Array(12) month[0]="1月" month[1]="2月" month[2]="3月" month[3]="4月" month[4]="5月" month[5]="6月" month[6]="7月" month[7]="8月" month[8]="9月" month[9]="10月" month[10]="11月" month[11]="12月" var day=new Array(7) day[0]="日" day[1]="一" day[2]="二" day[3]="三" day[4]="四" day[5]="五" day[6]="六" var today=myday.getFullYear()+"年"+month[myday.getMonth()]+myday.getDate()+'日'+" "+" "+myday.getHours()+"時"+myday.getMinutes()+"分"+myday.getSeconds()+"秒"+" "+" "+" "+" "+"星期"+day[myday.getDay()] document.getElementById("but").value=today; } </script> </head> <body style="background-color:#282923;"> <div> <input type="text" id="but" name="time" placeholder="點擊獲取當前時間" value=""> <button onclick="myclick()">點擊獲取當前時間</button> </div> </body> </html>
Correcting teacher:查無此人Correction time:2019-07-10 13:21:34
Teacher's summary:完成的不錯。js的日期時間,多用作選擇日期時間。日期時間處理,一般都是php來做。繼續(xù)加油