javascript 使用 Plunker,如何从浏览器控制台访问变量

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17666179/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 09:07:40  来源:igfitidea点击:

Using Plunker, How to access variable from the browser console

javascriptplunker

提问by Mike Barlow - BarDev

I'm using Plunker (http://plnkr.co/) to test JavaScript. From the browser console I want to access variables that I defined in the script.

我正在使用 Plunker ( http://plnkr.co/) 来测试 JavaScript。我想从浏览器控制台访问我在脚本中定义的变量。

In Plunker, can anyone tell me how to access the variable "someValue" from the browser console.

在 Plunker 中,谁能告诉我如何从浏览器控制台访问变量“someValue”。

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
</head>
<body>
    <script type="text/javascript">
      var someValue = 3
      console.log(someValue);
    </script>
</body>
</html>

回答by Mike Barlow - BarDev

I figured out one possible solution. In Google Chrome's Developer Tools on the bottom of the developer console "top frame" can be changed to "run.plnkr.co" (see image below). This will change the scope of the console and the variables in the script can now be accessed.

我想出了一种可能的解决方案。在 Google Chrome 的开发者工具中,开发者控制台底部的“顶框”可以更改为“run.plnkr.co”(见下图)。这将更改控制台的范围,现在可以访问脚本中的变量。

Plunker in Google Chrome

谷歌浏览器中的Plunker

Here's the answer for jsFiddle: Access variables in jsFiddle from Javascript console?

这是 jsFiddle 的答案: Access variables in jsFiddle from Javascript console?

回答by Nadir

or you can use http://jsbin.com/which displays the console directly

或者您可以使用直接显示控制台的http://jsbin.com/

回答by DL Narasimhan

using a separate window helped me debug the scopes and everything.

使用单独的窗口帮助我调试范围和所有内容。

just follow as below, and then use F12

只需按照以下步骤操作,然后使用F12

expand to a seperate window

展开到一个单独的窗口

回答by jcdsr

Try to use console.debug( variable );

尝试使用console.debug( variable );

Take a look in this post as well:

也看看这篇文章:

Difference between console.log() and console.debug()?

console.log() 和 console.debug() 的区别?