好好学习,天天向上
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>进击的巨人--JS</title>
<script>
var fishc="劳资是全局变量"; //定义一个全局变量
//函数定义
function myfunction() {
var fishc="小妞儿哪里跑,让你变成局部变量!";
alert(fishc);
}
//外部调用
myfunction();
alert(fishc);
</script>
</head>
<body>
</body>
</html>
我知道,用global就会变成全局了{:10_256:} 在函数内部声明的变量,仅对当前函数体有效,出了{}就无效{:10_256:} shishunfu 发表于 2017-6-9 09:23
忙碌了一段时间。
好好学习,天天向上
欢迎回归 学过一门语言后再学js感觉好轻松~
<!DOCTYPE html>
<html>
<head>
<title>局部变量</title>
</head>
<body>
<script type="text/javascript">
var fishc = '劳资是全局变量!';
function func(){
var fishc = '小妞儿哪里跑,让你变成局部变量';
alert(fishc);
}
func();
alert(fishc);
</script>
</body>
</html> {:5_91:} 暖贴{:10_254:} <!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> <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<title>title</title>
<script type="text/javascript">
var x = '我是全局变量!';
alert(x);
function myfunction(argument) {
// body...
var x = "把你变成局部变量!"
alert(x);
}
myfunction();
alert(x);
</script>
</head>
<body>
</body>
</html> alert({:10_250:})
<!DOCTYPE html>
<html lang="en">
<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>让编程改变世界</title>
</head>
<body>
<script type="text/javascript">
var fishc="我是全局变量";
function myfunction (){
var fishc = "我是局部变量";
alert(fishc);
}
myfunction();//此处调用可以不写名称,因为在myfunction中已经存储了fishc
alert(fishc);
</script>
</body>
</html> 学习了{:10_333:}
页:
[1]