gpt4 book ai didi

javascript - 如何将javascript局部变量转换为全局变量?

转载 作者:行者123 更新时间:2023-12-03 06:22:30 25 4
gpt4 key购买 nike

如何在 JavaScript 中将局部变量转换为全局变量?

喜欢

window.addEventListener("load", function () {

var fakeRadioButtonsFranType = document.querySelectorAll(".iCheck-helper");
for (var i = 0; i < fakeRadioButtonsFranType.length; i++) {
fakeRadioButtonsFranType[i].addEventListener("click", function () {
fran_type = Number(this.parentNode.querySelector("input").value);

var dataPass = 'fran_type=' + fran_type;
$.ajax({ // Send the username val to available.php
type: 'POST',
data: dataPass,
url: '<?= site_url('Alluser/getLocations'); ?>',
success: function (responseText) { // Get the result

var allZonals = responseText;
}
});
});
}
});

我想使用 allZonals 变量。

最佳答案

您可以将其分配给全局window对象:

window.allZonals = responseText;

关于javascript - 如何将javascript局部变量转换为全局变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38803952/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com