week5.md - mozi5269/wp109b GitHub Wiki

F12 Console 直接寫程式

不用w3school了

使用老師gitlab程式碼

改內容

<button type="button" onclick='document.getElementById("demo").innerHTML = "Hello JavaScript!"'>Click Me!</button>

令JavaScript can change HTML content = demo

1. document.getElementById("demo")
--> <p id="demo">JavaScript can change HTML content.</p>
2. document.getElementById("demo").innerHTML
--> "JavaScript can change HTML content."
3. document.getElementById("demo").innerHTML = "Hello!"
--> "Hello!"
4. document.getElementById("demo").innerHTML = "<a href="http://tw.youtube.com>"Youtube<a/>
--> "<a href="http://tw.youtube.com>"Youtube<a/> (超連結)
file:///C:/code/wp109b/week5/jsHello.html(範例)

改大小

<button type="button" onclick="document.getElementById('demo').style.fontSize='35px'">Click Me!</button>

The <script> Tag

<script>
document.getElementById("demo").innerHTML = "My First JavaScript";
</script>

(函數類型)
function myFunction() {
  document.getElementById("demo").innerHTML = "Paragraph changed.";

(函數 另一個檔案)
<script src="myScript.js"></script>
⚠️ **GitHub.com Fallback** ⚠️