行业知识
前端定义了全局变量后,再定义一个同名的局部变量
2026-11-27 01:16:34
来源:互联网转载
先说���论:不要这样定义,不然会发生莫名其妙的错误。
()问题叙述
前端定义了全局变量
var selectedSheet;
在后面的函数中又定义局部变量
()function switchToSheet() { var selectedSheet = document.getElementById('selectSheet').value; fetch('/get_data') .then(response => response.json()) .then(data => { hot.loadData(data[selectedSheet]); }) .catch(error => console.error('Error switching sheet:', error)); } 此时我要把数据打包传回后端
body: JSON.stringify({ sheet_name: selectedSheet, // 将当前选中的下拉框值传递给后端 data: hot.getData() // 将当前表格数据传递给后端}) 问题出现了,返回到后端的数据只有data,而一直拿不到sheet_name,把局部变量取消,直接使用全局变量,问题解决了!
道阻且长,行则将至。
上一篇:海康监控怎么上服务器?
下一篇:泰亚史诗怎么选服务器?