![JS 函数给全局变量赋值,第1张 JS 函数给全局变量赋值,第1张](/aiimages/JS+%E5%87%BD%E6%95%B0%E7%BB%99%E5%85%A8%E5%B1%80%E5%8F%98%E9%87%8F%E8%B5%8B%E5%80%BC.png)
你的意思是把局部变量的值赋给全局变量吧我举个例子吧:<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,看看值有没有变此时吧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