我想知道我是否可以通过一些命令清理控制台..
console.log()
,可以打印...是否有清除控制台的命令?..
我试过console.log(console);
并在下方获得了这个功能......
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
[我猜没有办法清理控制台......但是我想让别人对我这么说......]
答案 0 :(得分:287)
更新:截至2012年11月6日,Chrome浏览器中的
console.clear()
为now available。
如果您在控制台中键入clear()
,则会将其清除。
我认为没有办法以编程方式执行此操作,因为它可能会被滥用。 (控制台被某些网页清除,最终用户无法访问错误信息)
一种可能的解决方法:
在控制台类型window.clear = clear
中,您就可以在页面上的任何脚本中使用clear。
答案 1 :(得分:127)
总是有很好的技巧:
console.log("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
不是最优雅的解决方案,我知道:) ...但是有效。
对我来说,我通常只打印一个长的“-----”分隔线,以帮助简化日志阅读。
答案 2 :(得分:32)
这似乎工作正常:
console.clear();
答案 3 :(得分:19)
如果您使用console.clear()
,那似乎适用于Chrome。注意,它将输出“控制台已清除”消息。
注意,我在清除控制台后立即收到错误,因此它不会禁用控制台,只会清除它。另外,我只在chrome中试过这个,所以我不知道它是如何跨浏览器的。
编辑:我在Chrome,IE,Firefox和Opera中对此进行了测试。它适用于Chrome,MSIE和Opera的默认控制台,但不适用于Firefox,但它可以在Firebug中使用。
答案 4 :(得分:14)
如果您只想在调试时清除控制台,只需单击“禁用圈”⃠
按钮即可清除console.log。
或者只需按“Ctrl + L”即可使用键盘清除控制台。
答案 5 :(得分:12)
铬:
console._commandLineAPI.clear();
Safari浏览器:
console._inspectorCommandLineAPI.clear();
您可以创建自己的变量,该变量适用于:
if (typeof console._commandLineAPI !== 'undefined') {
console.API = console._commandLineAPI;
} else if (typeof console._inspectorCommandLineAPI !== 'undefined') {
console.API = console._inspectorCommandLineAPI;
} else if (typeof console.clear !== 'undefined') {
console.API = console;
}
之后,您只需使用console.API.clear()
。
答案 6 :(得分:8)
Press
CTRL+L
清除log
的快捷方式,即使您勾选了Preserve log
选项。
希望这可以帮助。
答案 7 :(得分:8)
你可以使用
console.clear();
如果您正在使用javascript编码。
否则你可以使用CTR+L
来清除cosole编辑器。
答案 8 :(得分:7)
在Mac上,您也可以像在终端中一样使用⌘+K
。
答案 9 :(得分:5)
console._inspectorCommandLineAPI.clear()
这是有效的
答案 10 :(得分:4)
在Chrome控制台上右键单击鼠标,我们可以选择清除控制台
答案 11 :(得分:4)
不要输入命令,只需按:
清除Chrome控制台
答案 12 :(得分:3)
基于Cobbal的回答,这就是我的所作所为:
在我的JavaScript
中,我提出以下内容:
setInterval(function() {
if(window.clear) {
window.clear();
console.log("this is highly repeated code");
}
}, 10);
条件代码将不会运行,直到你ASSIGN window.clear(意味着你的日志是空的,直到你这样做)。 在调试控制台类型中:
window.clear = clear;
Mac OS 10.6.8 - Chrome 15.0.874.106
答案 13 :(得分:3)
在Chrome中本地调试时,我使用以下命名来代替cls
(在控制台中输入以下JavaScript):
Object.defineProperty(window, 'cls', {
get: function () {
return console.clear();
}
});
现在在控制台中输入cls
将清除控制台。
答案 14 :(得分:3)
Chrome - 在关注控制台输入的同时按 CTRL + L 。
Firefox - clear()
在控制台输入中。
Internet Explorer - 在关注控制台输入的同时按 CTRL + L 。
边缘 - 在聚焦控制台输入的同时按 CTRL + L 。
祝你有个美好的一天!
答案 15 :(得分:3)
以编程方式清除控制台的多个答案的便捷汇编(来自脚本,不控制台本身):
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
}
答案 16 :(得分:2)
在 MacOS 上:
在 Linux 上:
在 Windows 上:
要使其在Firefox中运行,可以使用userscripts
。下载FF的GreaseMonkey
扩展名。
document.addEventListener("keydown",function(event){
if(event.metaKey && event.which==75) //CMD+K
{
console.clear();
}
});
在脚本中,使用值//@include *://*/*
更新元数据,以使其在每个页面上运行。仅当焦点位于页面上时,它将起作用。这只是一种解决方法。
答案 17 :(得分:1)
我认为由于“安全问题”,这已不再可用。
来自代码的 console.log(console)
给出了:
Console
memory: MemoryInfo
profiles: Array[0]
__proto__: Console
从代码外部,_commandLineAPI可用。有点烦人,因为有时候我只想记录而不是看旧输出。
答案 18 :(得分:-1)
我要补充一点,因为这是一个在Google上出现的搜索...
当使用ExtJS / Javascript时,我插入此控制台并清除控制台 - 除非出现错误..
console.log('\033[2J');
我很可能偏离正轨,但这是我清除每个页面加载/刷新控制台的方式。