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

时间:2016-08-06 11:46:52

标签: 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变量。

1 个答案:

答案 0 :(得分:1)

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

window.allZonals = responseText;