Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

炫酷的 console 命令. #1

Open
Bloom2036 opened this issue Aug 16, 2017 · 0 comments
Open

炫酷的 console 命令. #1

Bloom2036 opened this issue Aug 16, 2017 · 0 comments

Comments

@Bloom2036
Copy link
Owner

Bloom2036 commented Aug 16, 2017

一、显示信息的命令

console.log('hello');
console.info('信息');
console.error('错误');
console.warn('警告');

二:占位符

console上述的集中度支持printf的占位符格式,支持的占位符有:字符(%s)、整数(%d或%i)、浮点数(%f)和对象(%o):

占位符 作用
%s 字符串
%d or %i 整数
%f 浮点数
%o 可展开的DOM
%O 列出DOM的属性
%c 根据提供的css样式格式化字符串
console.log("%d年%d月%d日",2011,3,26);

%o、%O都是用来输出Object对象的,对普通的Object对象,两者没区别,但是打印dom节点时就不一样了:

// 格式成可展开的的DOM,像在开发者工具Element面板那样可展开 
console.log('%o',document.body.firstElementChild); 
// 像JS对象那样访问DOM元素,可查看DOM元素的属性 
// 等同于console.dir(document.body.firstElementChild) 
console.log('%O',document.body.firstElementChild);

三:计时器

你可以启动一个计时器(timer)来跟踪某一个操作的占用时长。每一个计时器必须拥有唯一的名字,页面中最多能同时运行10,000个计时器。当以此计时器名字为参数调用 console.timeEnd() 时,浏览器将以毫秒为单位,输出对应计时器所经过的时间.

console.time("func");
console.timeEnd("func");

原文

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant