let gwpFun = ()=> {
var dom = document.getElementById("box4");
var myChart = echarts.init(dom);
var app = {};
option = null;
var y_f = [];
//全局变量,wgid在gognweizongtu.js中获取
var gwp = 0;
var xishu = [0.4, 0.2, 0.3, 0.1];
var pjx = ["gzp", "gyp", "wlp", "ryp"];
var pj = { "gongzhuang": "OK", "gongyi": "OK", "wuliao": "OK", "renyuan": "OK" };
var guige = [90, 90, 80, 75, 85];
var xiang = ["gongzhuang", "gongyi", "wuliao", "renyuan"];
for (var i = 0; i < xiang.length; i++) {
var lent = data[xiang[i]].y.length;
var ind = lent - 1;
y_f.push(data[xiang[i]].y[ind]);
if (data[xiang[i]].y[ind] < guige[i]) {
pj[xiang[i]] = "NOK";
}
document.getElementById(pjx[i]).innerHTML = pj[xiang[i]];
gwp += y_f[i] * xishu[i];
}
y_f.push(88);
if (gwp > 85.5) {
document.getElementById("gwpj").innerHTML = "OK";
}
gwp = gwp.toFixed(2);
document.getElementById("gwp").innerHTML = gwp;
document.getElementById("jinri").innerHTML = gwp;
document.getElementById("zuori").innerHTML = gwp;
document.getElementById("benzhou").innerHTML = gwp;
document.getElementById("lishi").innerHTML = gwp;
document.getElementById("gwp1").innerHTML = gwp1;
/*绘图代码省略*/
if (option && typeof option === "object") {
myChart.setOption(option, true);
}
return gwp;
}
gwpFun()
请采纳
定义到公共函数的任意位置都可以
把变量的值保存在页面的一个隐藏的text中,在另一个函数里读取这个text的值。试试这个方法
函数库中的变量一般都是封装好的 , 不会对外暴露, 但是可以写个get方法吧这个参数值返回出来就可以了。 一遍都是这样处理的。
把这句话 var gwp = 0;移到$(function(){上面