<p>全局变量在任何脚本和函数内均可访问。</p> <p id="demo"></p> <script> var carName = "Volvo"; myFunction(); function myFunction() { document.getElementById("demo").innerHTML = "我可以显示 " + carName; } </script>