猿问

在Google Chrome中清除JavaScript控制台

我想知道是否可以使用某些命令清除控制台。


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

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


心有法竹
浏览 724回答 3
3回答

米琪卡哇伊

console.clear()是现在可以在Chrome金丝雀。如果您输入clear()控制台,它将清除它。我认为没有办法以编程方式进行此操作,因为它可能会被滥用。(控制台已通过某些网页清除,最终用户无法访问错误信息)一种可能的解决方法:在控制台类型中window.clear = clear,则可以在页面上的任何脚本中使用clear。

达令说

总是有个好办法: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");我知道这不是最优雅的解决方案:) ...但是可以。对于我来说,我通常只打印一条长长的“ -----”分隔线以帮助使日志更易于阅读。

素胚勾勒不出你

铬:console._commandLineAPI.clear();苹果浏览器: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()。
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答