?????? ??
JavaScript ??
JavaScript? ????? HTML ??? ???? ? ?????.
JavaScript? ???? ??? ??
JavaScript? ??? ???? ???? ??? ? ????.
window.alert()? ???? ?? ??? ?????. document.write() ???? ???? HTML ??? ??? ???. HTML ??? ??? innerHTML? ?????. ???? ??? ??? console.log()? ?????.
HTML ?? ??
JavaScript?? HTML ??? ?????? document.getElementById(id) ???? ??? ? ????.
HTML ??? ????? "id" ??? ??????.
<!DOCTYPE html> <html> <body> <h1>My First Web Page</h1> <p id="demo">My First Paragraph</p> <script>document.getElementById("demo").innerHTML="My First JavaScript";</script> </body> </html>
?? JavaScript ?(<script> ??? ??)? ? ?????? ??? ? ????.
document.getElementById( "demo")? id ??? ???? HTML ??? ?? JavaScript ?????.
innerHTML = "??? ???????."? ??? HTML ???(innerHTML)? ???? ? ???? JavaScript ?????.
window.alert()
? ???? ?? ??? ???? ???? ??? ? ????.
<!DOCTYPE html> <html> <body> <h1>我的第一個頁面</h1> <p>我的第一個段落。</p> <script> window.alert('Hello Word!'); </script> </body> </html>
? ???????
???? ??, ? ??????? The ???? ?????. ??? ??? ?? ?????:
?? ???? id="demo"? <p> ??? HTML ?? ??? ?? ???.
HTML ??? ??
??? ???? HTML ??? JavaScript? ?? ??? ? ????.
<!DOCTYPE html> <html> <body> <h1>我的第一個 Web 頁面</h1> <p>我的第一個段落。</p> <script> document.write(Date()); </script> </body> </html>
??? ??? ??? document.write()? ?????.
?? ??? ??? ? document.write? ???? ?? HTML ???? ???? ???.
<!DOCTYPE html> <html> <body> <h1>我的第一個 Web 頁面</h1> <p>我的第一個段落。</p> <button onclick="myFunction()">點我</button> <script> function myFunction() { document.write(Date()); } </script> </body> </html>
Write to console
????? ???? ???? ?? console.log() ???? ???? ????? JavaScript ?? ??? ? ????.
?????? F12? ???? ??? ??? ????? ??? ??? "??" ??? ?????.
<!DOCTYPE html> <html> <body> <h1>我的第一個 Web 頁面</h1> <script> a = 5; b = 6; c = a + b; console.log(c); </script> </body> </html>
?????? ???? ??(??)? ????? ?? ??? ?????.