简体   繁体   English

如何在JQuery / javascript中设置全局变量

[英]How to set global variable in JQuery/javascript

Hi i am new to jquery/javascript. 嗨,我是jquery / javascript的新手。 I have created a global variable. 我创建了一个全局变量。 I set the value of value of this variable inside function like this: 我像这样在函数内部设置此变量的value的值:

var arr;
CreatecheckPassword: function() {

                var pas = document.getElementById("pos-password")

                var user = new db.web.Model("res.users").get_func("read")(this.session.uid, ['password']).pipe(function(result) {
                     arr = result.password;
                     alert(arr);//prints the expected value
                });
                alert(arr);//prints nothing
},

I don't know where i am doing wrong. 我不知道我在哪里做错了。 I tried hard but was unable to find the solution. 我努力尝试,但是找不到解决方案。 Can someone help. 有人可以帮忙吗?

jslint or jshint is your friend. jslint或jshint是您的朋友。 Get it and use it on your code to get lint messages. 获取它并在您的代码上使用它来获取皮棉消息。

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM