当前位置:网站首页>js更改全部变量失败后改成return方法,终于解决解决问题
js更改全部变量失败后改成return方法,终于解决解决问题
2022-04-23 05:55:00 【ZHZHK001】
最开始的失败方法
其中的c1 c2 是一个全局变量的名称
随着c1 c2 的不同,改变 对应名称的全局变量 的内容
下面我的代码是错误的,是无法改变全局变量的内容,不知道怎么更改
<script type="text/javascript">
var c1 = [{
id: 1, text: '广东' }];
var c2 = [{
id: 1, text: '广东' }];
function change(){
listDict("cost","0",c1);//改变c1的全局变量//调用区域
listDict("codddst","0",c2);
}
change();//设置为打开页面马上启动
//方法区域
function listDict(dtype,dPid,c){
……………………………………
Layers.AjaxProxy({
…………
data: data ,
dataType: 'json',,
}).done(function (result, flag) {
if (flag) {
//
……………………………………………………
c=…………;//这个是不会变化的
}//
});
}
</script>
后面的解决方法
解决思路是使用了return的方法
全局变量处改成c1 = 方法;方法中增加return
var c1 = [{
id: 1, text: '广东'}];
var c2 = [{
id: 1, text: '背景', pid: 1 }];
function changeSelect(){
//-----------------------------
c1 = listDict("costType","0",c1);//关键部分
c2 = listDict("costType","",c2);//
}
changeSelect();//设置为打开页面马上启动
function listDict(dtype,dPid,c){
……………………………………
Layers.AjaxProxy({
cache: false ,
type: "get" ,
url: "${request.contextPath}/d4d4/dddd" ,
data: data ,
dataType: 'json',
async: false ,
}).done(function (result, flag) {
if (flag) {
//
……………………………………………………
}//
});
return c;//关键部分
}
版权声明
本文为[ZHZHK001]所创,转载请带上原文链接,感谢
https://blog.csdn.net/weixin_43142925/article/details/105429785
边栏推荐
猜你喜欢
Overview of node file system and buffer
深蓝学院激光slam 理论与实践 第三章激光雷达去畸变 作业习题
FOC电机库 定点PID代码分析
几款笔记软件的优缺点
HDU-Tunnel Warfare
Informatics one book pass - small ball
Error in created hook: “ReferenceError: “Promise”未定义“
死区时间的分析与设置
Detailed explanation and application of PN junction and diode principle
uniapp 自定义搜索框适配小程序对齐胶囊
随机推荐
时间戳转格式化日期
C语言中volatile的使用
Use of C language and
说说ts的心里话
深蓝学院激光slam 理论与实践 第三章激光雷达去畸变 作业习题
ES6的新特性
Collection of practical tips for C language (continuously updated)
JS实现私有属性
token详解以及应用原理
POJ-The Unique MST
导入文件时候 new FormData()
小程序学习笔记(一)
监听除某元素之外点击事件
使用jsonwebtoken生成访问密钥
提交本地仓库并同步码云仓库
解析psd文件,并映射成组件
C language code specification
MOS tube characteristics and conduction process
Router对象、Route对象、声明式导航、编程式导航
Node accesses server-side static resources