如何在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变量。
答案 0 :(得分:1)
您可以将其分配给全局window
对象:
window.allZonals = responseText;