该问题是由于在加载和解析外部 JavaScript 文件之前调用 show3() 引起的。
<!DOCTYPE html>
<html>
<body>
<h2>My First Web Page</h2>
<p id="demo">First Paragraph</p>
<p id="demo2">Second Paragraph should be something different</p>
<script src="myScript.js"></script>
<script>
// Wait for the DOM content to fully load
document.addEventListener('DOMContentLoaded', function() {
show3(); // Safe to call now
});
</script>
</body>
</html>