一个JavaScript变量应用实例

实例代码:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>

</body>
<script type="text/javascript">
	var a = "全局变量";
	function aa() {
		alert(a); //undefined
		var a = "局部变量";
	}
	aa();
</script>
</html>

运行结果:

一个JavaScript变量应用实例

相关推荐