<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>Document</title>
</head>
<body>
</body>
<script type="text/javascript">
var num1 = 10;
function parent(){
var num2 = 20;
function son(){
var num3 = 30;
alert(num1);//10
alert(num1);//20
alert(num3);//30
}
son();
//不能访问子函数内部局部变量
//alert(num3);
}
parent();
//不能访问内部的局部变量
//alert(num3);
alert(num3);
</script>
</html>点击 "运行实例" 按钮查看在线实例
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号