为什么简单的console.log()不适用于?

时间:2014-12-22 13:31:22

标签: javascript html while-loop console.log

今天,我制作了经典的#99; 99瓶"当使用document.write()时,JavaScript.it正在工作。但是当我使用console.log()时,它表现得很奇怪。

console.log()代码-----

 var word = "bottles";
 var count = 99;
 while (count > 0) {
 console.log(count + " " + word + " of beer on the wall");
 console.log(count + " " + word + " of beer,");
 console.log("Take one down, pass it around,");
 count = count - 1;


}
 console.log("No more " + word + " of beer on the wall.");

上面的代码应该以" 99瓶开始....."但是它开始于" 67瓶......"。为什么这样正在发生? 小提琴 - http://jsfiddle.net/vashuStrPro/9dobfj8h/

1 个答案:

答案 0 :(得分:1)

问题在于您的开发人员控制台的限制..而不是您的代码..

我已更新您的代码 - >它将您的文本附加到divcontainer ... start 99 end 1

JavaScript的:

var word = "bottles";
var div = document.getElementById('tmp');

for (var count = 99; count > 0; --count) {
    div = document.getElementById('tmp');
    div.innerHTML = div.innerHTML + count + " " + word + " of beer on the wall<br>";
    div.innerHTML = div.innerHTML + count + " " + word + " of beer,<br>";
    div.innerHTML = div.innerHTML + "Take one down, pass it around,<br>";
}

div.innerHTML = div.innerHTML + "No more " + word + " of beer on the wall.";

HTML:

<div id="tmp">
</div>

评论后回答:

的FireFox

在地址栏中输入about:config,然后为龙选择确定。

将此类型输入过滤器

devtools.hud.loglimit.console

你可以设置你的限制......