<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=script, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>变量作用域</title>
</head>
<body>
<script type="text/javascript">
var name = "鱼C根部 ";
var hahaha = "哈哈这回我有定义了";
//函数的定义
function first_function(){
name = name + "守护鱼C黑夜的组织 ";
address = " 快来加入吧~";
}
//函数的调用
first_function();
alert("鱼C神秘组织:" + name + " 光耀豪杰" + address);
alert(hahaha);
</script>
<script type="text/javascript">
var fishc = "老子是全局变量";//定义全局变量
function myFunction(){
var fishc = "小妞儿,哪里跑,让你变成全局变量!";
alert(fishc);
}
myFunction();
alert(fishc);
</script>
</body>
</html>
|