0
如何在JavaScript中将局部变量转换为全局变量?如何将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变量。
申报到窗口对象。 – Jain
'window.allZonals = allZonals'。或者不要将它声明为'var',而只是使用'window.allZonals' – vlaz
分配给窗口对象或在全局范围内创建,并且只需修改 –