源代码
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>享学课堂</title> <script> function myFunction() { document.getElementById("demo").innerHTML = "段落被改变."; } </script> </head> <body> <h1>JavaScript在Head里面</h1> <p id="demo">一个段落.</p> <button type="button" onclick="myFunction()">试试</button> </body> </html>
运行结果