javascript里面函数赋值给变量的问题

JavaScript08

javascript里面函数赋值给变量的问题,第1张

此时吧name函数赋值给a的意义是什么? var a=function name(){alert("对话")} 这样写的话 a的值 就是 function name(){alert("对话")} 这个字符串!!! document.write(a)//输出的就是function name(){alert("对话")} 这句话 document.write(a()) //输出的就是 对话 也就是说 name 函数变成了 a 函数 要调用name时如何调用呢? 调用函数 可以 这样: function name(){alert("对话")} var a = name() document.write(a) //这样 输出的就是对话框 再就是 undefined 空值 var ab = function name2(){return false} document.write(ab) //输出的 就是 false

你的意思是把局部变量的值赋给全局变量吧我举个例子吧:<input type=“button” value=“1” onclick="MicroNet_OnSubmit('bbb')" ><input type=”button“ value=”2“ onclick="MicroNet_OnSubmit1()" ><script>var liuyin="aaa"function MicroNet_OnSubmit(flvFile) { liuyin= flvFile}function MicroNet_OnSubmit1() {alert(liuyin)} </script>上面的代码放在htm文件里,先点击按钮1再点击按钮2,看看值有没有变