改變html.,沒有樣式???為什么?
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>改變html樣式文檔</title>
<script type="text/javascript">
var mychar=document.getEelmentById("con");
? mychar.style.color="red";
? mychar.style.fontsize="36px";
? mychar.style.width="300px";
? mychar.style.backgroundcolor="#ccc";
</script>
</head>
<body>
<h2 id="con">I love javascript.</h2>
<p>javascript代表了網頁的行為。</p>
</body>
</html>

2016-05-19
document.getElement
2016-05-19
var?mychar=document.getElementById("con"); mychar.style.backgroundColor="#ccc";getElementById
backgroundColor
按順序執行,如果script代碼在文本上方則無法在執行到<h2>標簽時調用Javascript,可以通過添加函數來調用上面的代碼。也可以把javascript代碼寫在<h2>標簽下。
<!DOCTYPE?HTML> <html> <head> <meta?http-equiv="Content-Type"?content="text/html;?charset=utf-8"?/> <title>style樣式</title> </head> <body> ??<h2?id="con">I?love?JavaScript</H2> ??<p>?JavaScript使網頁顯示動態效果并實現與用戶交互功能。</p> ??<script?type="text/javascript"> ????var?mychar=document.getElementById("con"); ????mychar.style.color="red"; ????mychar.style.backgroundColor="#ccc" ????mychar.style.width="300px"; ??</script> </body> </html>2016-05-19