我正在尝试更改嵌套函数中的函数内部声明的变量的值。但这不起作用。这是一个例子
function foo() {
var str = "";
function foo1() {
str = "hello";
}
foo1();
alert(str); // it shows nothing
}
<input type="button" onclick="foo()">
您可能需要将字符串设置为的返回值foo1()
。
function foo() {
function foo1(){
return "bar";
}
var str = foo1();
alert(str);// it shows "bar"
}
foo();
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句