我想知道我是否可以清除控制台的一些命令。

Console.log(),可以打印…是否有清除控制台的命令?

我已经尝试console.log(控制台);得到下面这个函数。

assert: function assert() { [native code] }
constructor: function Console() { [native code] }
count: function count() { [native code] }
debug: function debug() { [native code] }
dir: function dir() { [native code] }
dirxml: function dirxml() { [native code] }
error: function error() { [native code] }
group: function group() { [native code] }
groupEnd: function groupEnd() { [native code] }
info: function info() { [native code] }
log: function log() { [native code] }
markTimeline: function markTimeline() { [native code] }
profile: function profile() { [native code] }
profileEnd: function profileEnd() { [native code] }
time: function time() { [native code] }
timeEnd: function timeEnd() { [native code] }
trace: function trace() { [native code] }
warn: function warn() { [native code] }
__proto__: Object

我想没有办法清理控制台……但我希望有人对我说……]


当前回答

按CTRL+L快捷键清除日志,即使您选择了保存日志选项。 希望这能有所帮助。

其他回答

我认为由于“安全问题”,这已不再可用。

console.log(console)代码给出:

Console
memory: MemoryInfo
profiles: Array[0]
__proto__: Console

在代码外部,_commandLineAPI是可用的。有点烦人,因为有时我只想记录而不看到旧的输出。

在Chrome控制台用鼠标右键点击,我们有清除控制台的选项

根据Cobbal的回答,以下是我的做法:

在我的JavaScript,我把以下:

setInterval(function() {
  if(window.clear) {
    window.clear();
    console.log("this is highly repeated code");
  }
}, 10);

条件代码在你ASSIGN窗口之前不会运行。清除(意思是您的日志是空的,直到您这样做)。在调试控制台类型中:

window.clear = clear;

Violà -一个自我清除的日志。

Mac OS 10.6.8 - Chrome 15.0.874.106

一个方便的编译,用于以编程方式清除控制台的多个答案(从脚本,而不是控制台本身):

if(console._commandLineAPI && console._commandLineAPI.clear){
    console._commandLineAPI.clear();//clear in some safari versions
}else if(console._inspectorCommandLineAPI && console._inspectorCommandLineAPI.clear){
    console._inspectorCommandLineAPI.clear();//clear in some chrome versions
}else if(console.clear){
    console.clear();//clear in other chrome versions (maybe more browsers?)
}else{
    console.log(Array(100).join("\n"));//print 100 newlines if nothing else works
}

在Mac上,你也可以像在终端中一样使用⌘+K。