打開console控制檯能直接看到有些網站的招聘信息直接顯示在控制檯裏,比如百度、去哪兒網。這些怎麼搞呢?先看下官方的API吧
console.log() 官方API
Format Specifier | Description |
---|---|
%s | Formats the value as a string. |
%d or %i | Formats the value as an integer. |
%f | Formats the value as a floating point value. |
%o | Formats the value as an expandable DOM element (as in the Elements panel). |
%O | Formats the value as an expandable JavaScript object. |
%c | Formats 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');