控制台访问$(文档).ready函数本地的JavaScript变量 [英] Console access to Javascript variables local to the $(document).ready function

查看:110
本文介绍了控制台访问$(文档).ready函数本地的JavaScript变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何访问内部的一些变量

How can I access some variables inside

$(document).ready(function(){
    var foo=0;
    var bar = 3;
});

如果我尝试alert(foo),我会得到一个消息,它没有被定义。

from Google chrome console? If I try alert(foo), I will get a message that it is not defined.

推荐答案

在调试器中放置一个断点。

Put a breakpoint with the debugger. You'll get full access to them when the debugger will stop.

其他答案告诉你把它们放在全局范围内是不好的。不要仅仅因为你不知道如何使用正确的工具而使用不良做法。

Other answers telling you to put them in the global scope are bad. Don't use bad practices just because you don't know how to use the right tools.

这篇关于控制台访问$(文档).ready函数本地的JavaScript变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆