我如何从我的JavaScript打印一些东西到JsFiddle的结果屏幕。我不能使用document.write(),它不允许,也不允许打印。

我应该用什么?


当前回答

为此我有一个模板;以下是我使用的代码:

HTML

<pre id="output"></pre>

JavaScript

function out()
{
    var args = Array.prototype.slice.call(arguments, 0);
    document.getElementById('output').innerHTML += args.join(" ") + "\n";
}

示例使用(JavaScript)

out("Hello world!");
out("Your lottery numbers are:", Math.random(), 999, Math.PI);
out("Today is", new Date());

其他回答

只是添加一些可能对一些人有用的东西....

如果你添加如上所示的调试器控制台,你可以通过执行以下命令来访问范围:

scope = angular.element(document.querySelector('[ng-controller=MyCtrl]')).scope();

我发现直接检查作用域比console.log、alert()等更容易。

为此我有一个模板;以下是我使用的代码:

HTML

<pre id="output"></pre>

JavaScript

function out()
{
    var args = Array.prototype.slice.call(arguments, 0);
    document.getElementById('output').innerHTML += args.join(" ") + "\n";
}

示例使用(JavaScript)

out("Hello world!");
out("Your lottery numbers are:", Math.random(), 999, Math.PI);
out("Today is", new Date());

为了能够在JSFiddle中看到console.log()的输出,请转到左侧面板的外部资源,并为Firebug添加以下链接:

https://getfirebug.com/firebug-lite-debug.js

你可以这样做——> http://jsfiddle.net/chY5y/

$('body').append(yourVariable); 

使用alert()函数:

alert(variable name);
alert("Hello World");