console花式log

由 Jefsky 发布于 2024-01-04

console.log利用占位符格式化打印
%c表示css样式

    console.log('%c hello jefsky', 'color: yellow;font-size: 24px;font-weight: bold;text-decoration: underline;');

%d 或 %i表示整型

    console.log('%d', 123);

    console.log('%i', 123);

%f表示浮点型

     console.log('%f', 123.321);

%o表示DOM元素

    console.log('%o', document.body);

%O表示javascript对象

    console.log('%O', new Date());

console对象的其他属性

assert: ƒ assert()

clear: ƒ clear()

context: ƒ context()

count: ƒ count()

countReset: ƒ countReset()

debug: ƒ debug()

dir: ƒ dir()

dirxml: ƒ dirxml()

error: ƒ error()

group: ƒ group()

groupCollapsed: ƒ groupCollapsed()

groupEnd: ƒ groupEnd()

info: ƒ info()

log: ƒ log()

memory: (...)

profile: ƒ profile()

profileEnd: ƒ profileEnd()

table: ƒ table()

time: ƒ time()

timeEnd: ƒ timeEnd()

timeLog: ƒ timeLog()

timeStamp: ƒ timeStamp()

trace: ƒ trace()

warn: ƒ warn()

有兴趣的可以在你的浏览器console中尝试一下