javascript 在 JsFiddle 中打印 Var

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17382200/
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 08:06:57  来源:igfitidea点击:

Print Var in JsFiddle

javascriptjsfiddle

提问by aritroper

How would I print something to the result screen in JsFiddle from my JavaScript. I can't use document.write(), it doesn't allow it, neither print.

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

What should I use?

我应该使用什么?

回答by davidkelleher

To be able to see output from console.log()in JSFiddle, go to External Resourceson the left-side panel and add the following link for Firebug:

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

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

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

Example of the result after adding firebug-lite-debug.js

添加 firebug-lite-debug.js 后的结果示例

回答by IQAndreas

I have a template for this purpose; here is the code I use:

我有一个用于此目的的模板;这是我使用的代码:

HTML

HTML

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

JavaScript

JavaScript

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

Sample use (JavaScript)

示例使用(JavaScript)

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

回答by Flame Trap

Try:

尝试:

document.getElementById('element').innerHTML = ...;

Fiddle: http://jsfiddle.net/HKhw8/

小提琴:http: //jsfiddle.net/HKhw8/

回答by Euphe

Might not do what you do, but you can type

可能不会做你做的事,但你可以打字

console.log(string)

And it will print the string into the console of your browser. In chrome push CTRL+ SHIFT+ Jto open the console.

它会将字符串打印到浏览器的控制台中。在Chrome推CTRL+ SHIFT+J打开控制台。

回答by Mohammad Adil

You can do this --->http://jsfiddle.net/chY5y/

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

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

回答by vkabachenko

Now jsfiddle can do it from the scratch. Just go to Javascrpt --> Frameworks & extensions --> Jquery(edge) and check Firebug lite checkbox

现在 jsfiddle 可以从头开始。只需转到 Javascrpt --> 框架和扩展 --> Jquery(edge) 并选中 Firebug lite 复选框

回答by Igor Vaschuk

document.body.innerHTML = "Your data";

document.body.innerHTML = "你的数据";

回答by JohnPan

With ES6 tricks could be

使用 ES6 技巧可能是

function say(...args)
{ 
    document.querySelector('#out').innerHTML += args.join("</br>");
}
say("hi","john");

Add only

仅添加

 <span id="out"></span>

in HTML

在 HTML 中

回答by skibulk

Here's one alternative: http://jsfiddle.net/skibulk/erh7m9og/1/

这是一种替代方法:http: //jsfiddle.net/skibulk/erh7m9og/1/

document.write = function (str) {
    document.body.insertAdjacentHTML("beforeend", str);
}

document.write("?hola mundo");

回答by Neph

Just to add something that might be useful to some folks....

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

If you add the debugger console as shown above, you can access the scope by executing this:

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

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

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

I find inspecting the scope directly easier than console.log, alert(), etc.

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