abstrak: 首先講的是HTML DOM,改變HTML元素內(nèi)容innerHTML,格式:getElementById ("id 名稱").innerHTML ="改變的內(nèi)容";還可以通過(guò)class名(ClassName) 標(biāo)簽名(TagName)去改變,也可以去改變HTML的屬性值,必須是HTML標(biāo)簽的自帶屬性,格式 :getElem
首先講的是HTML DOM,改變HTML元素內(nèi)容innerHTML,格式:getElementById ("id 名稱").innerHTML ="改變的內(nèi)容";還可以通過(guò)class名(ClassName) 標(biāo)簽名(TagName)去改變,也可以去改變HTML的屬性值,必須是HTML標(biāo)簽的自帶屬性,格式 :getElementById("").屬性名稱="屬性值";
改變CSS的樣式,格式:getElementById("id名稱").style.屬性名稱 ="屬性值";
時(shí)間和日期:獲取當(dāng)前時(shí)間var now =new Date();獲取年月星期幾日時(shí)分秒分別是:now.getFullYear; now.getmonth; now.getDay; now.getDate; now.getHours; nowgetMinutes; now.getSeconds;
小案例時(shí)間函數(shù):
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Time_Function</title>
<link rel="stylesheet" type="text/css" href="../css/css.css">
<link rel="shortcut icon" type="image/x-icon" href="../pictcure/mi.png">
<style type="text/css">
</style>
</head>
<body>
<script type=text/javascript>
var now=new Date;//獲取當(dāng)前時(shí)間
// console.log(now);
//時(shí)間函數(shù)
function time (a){
var y=a.getFullYear();
var m=a.getMonth();
var d=a.getDate();
var h=a.getHours();
var m=a.getMinutes();
var s=a.getSeconds();
//顯示年月日時(shí)分秒
document.write(y+"-"+m+"-"+d+" "+h+":"+m+":"+s);
//document.write(a.getMonth())
}
var b=time(now);
console.log(b);
</script>
</body>
</html>
老師 有個(gè)問(wèn)題,為什么我單獨(dú)去截取出月份就是對(duì)的,程式運(yùn)行出來(lái)的月份不對(duì),最后 總會(huì)出現(xiàn)一個(gè)undefined是什么意思呀?問(wèn)題找不出來(lái),老師幫幫忙了。
Guru membetulkan:韋小寶Masa pembetulan:2018-11-26 14:53:56
Rumusan guru:下次作業(yè)中的代碼記得加上高亮!undefined是未定義的意思?。∧闼搅囊幌挛?!把報(bào)錯(cuò)截圖發(fā)給我