如何将javascript本地变量转换为全局可验证变量

How convert javascript local variable to global veriable?

本文关键字:变量 转换 全局 可验证 javascript      更新时间:2023-09-26

如何在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;