当前位置:网站首页>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
边栏推荐
猜你喜欢
随机推荐
The difference between single quotation mark, double quotation mark and back quotation mark in shell script
Arm common assembly instructions
统计字符串中每个字符出现的次数
Wildcards and special symbols for shell scripts
Aperçu de Redux
POJ-The Unique MST
js获取链接?后边的参数名称或者值,根据url ?后的参数做判断
监听除某元素之外点击事件
Redux概述
HDU-Memory Control
C51/C52 特殊功能寄存器表
Use of shell scripts & and 𞓜
【ORACLE与mysql的区别】
C语言代码规范
Makefile foundation, common functions and general makefile
提交本地仓库并同步码云仓库
POJ-The Unique MST
v-for下定时给图片添加动画
汇编基础代码示例
Krypton binary