我如何从我的JavaScript打印一些东西到JsFiddle的结果屏幕。我不能使用document.write(),它不允许,也不允许打印。
我应该用什么?
我如何从我的JavaScript打印一些东西到JsFiddle的结果屏幕。我不能使用document.write(),它不允许,也不允许打印。
我应该用什么?
当前回答
document.body.innerHTML = "你的数据";
其他回答
为此我有一个模板;以下是我使用的代码:
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());
也许不能做你做的事,但你可以打字
console.log(string)
它会把字符串打印到浏览器的控制台。在chrome浏览器中按CTRL + SHIFT + J打开控制台。
为了能够在JSFiddle中看到console.log()的输出,请转到左侧面板的外部资源,并为Firebug添加以下链接:
https://getfirebug.com/firebug-lite-debug.js
使用alert()函数:
alert(variable name);
alert("Hello World");
这里有一个替代方案:http://jsfiddle.net/skibulk/erh7m9og/1/
document.write = function (str) {
document.body.insertAdjacentHTML("beforeend", str);
}
document.write("¡hola mundo");