為什么把<script></script>放到<head>標簽里就無效?。?/h1>
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>style樣式</title>
<script type="text/javascript">
? ? var mychar= document.getElementById("con");
? ? mychar.style.color="red";
? ? machar.style.backgroundColor="#CCC";
? ? machar.style.width="300px";
?</script>
</head>
<body>
? <h2 id="con">I love JavaScript</H2>
? <p> JavaScript使網頁顯示動態效果并實現與用戶交互功能。</p>
</body>
</html>
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>style樣式</title>
<script type="text/javascript">
? ? var mychar= document.getElementById("con");
? ? mychar.style.color="red";
? ? machar.style.backgroundColor="#CCC";
? ? machar.style.width="300px";
?</script>
</head>
<body>
? <h2 id="con">I love JavaScript</H2>
? <p> JavaScript使網頁顯示動態效果并實現與用戶交互功能。</p>
</body>
</html>
2022-04-25
script 是腳本(腳)的意思,他的功能是主要寫邏輯的,應該防在body后面,不能放到head(頭)里面。