打开console控制台能直接看到有些网站的招聘信息直接显示在控制台里,比如百度、去哪儿网。这些怎么搞呢?先看下官方的API吧

console.log() 官方API

Format SpecifierDescription
%sFormats the value as a string.
%d or %iFormats the value as an integer.
%fFormats the value as a floating point value.
%oFormats the value as an expandable DOM element (as in the Elements panel).
%OFormats the value as an expandable JavaScript object.
%cFormats the output string according to CSS styles you provide.

直接上代码

if (window.console) {
    console.log('你好\n\n\n欢迎你。');
    console.log("css样式%c这里会变色", "color:red;font-weight:bold;");
}

如果需要图片也可以用css去引入

if (window.console) {
	console.log("%c图片显示","padding-left:120px; padding-bottom:40px; background:url('路径') no-repeat") 
}

当然也可以经过一些处理用字符串显示
通过这个网站patorjk.com生成字符串形式的图画

 Function.prototype.makeMulti = function () {
     let l = new String(this)
     l = l.substring(l.indexOf("/*") + 3, l.lastIndexOf("*/"))
     return l
 }

 let string = function () {
   /* 你复制patorjk.com上的字符图案 */
 }
 console.log(string.makeMulti());
 //也可以这样
 console.log(`%c${string.makeMulti()}`,'color:red');
Logo

CSDN联合极客时间,共同打造面向开发者的精品内容学习社区,助力成长!

更多推荐