源代码
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>享学课堂</title> </head> <body> <p> 在HTML中,所有的全局变量将成为窗口window变量。 </p> <p id="demo"></p> <script> var carName = "Volvo"; // code here can use window.carName document.getElementById("demo").innerHTML = "I can display " + window.carName; </script> </body> </html>
运行结果