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

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

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


当前回答

根据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
}

当在Chrome中本地调试时,我使用以下方法来别名cls(将以下JavaScript输入控制台):

Object.defineProperty(window, 'cls', {
    get: function () {
        return console.clear();
    }
});

现在在控制台中输入CLS将清除控制台。

如果你只是想在调试时清除控制台,你可以简单地点击“ban-circle”⃠按钮来清除console.log。

或者,只需按“Ctrl+L”来清除控制台使用你的键盘。

不用输入command,只需按:

CLTRL + L

清除chrome控制台

我要补充一点,因为这是谷歌上的搜索结果。

当使用ExtJS / Javascript时,我插入这个,控制台被清除-除非有错误。

console.log('\033[2J');

我很可能偏离了轨道,但这就是我在每次页面加载/刷新时清除控制台的方式。