10
09/2014
chrome console log color
给 console 点颜色看看!
function clog(msg, color) {
if(color){
console.log("%c" + msg, "color:" + color + ";font-weight:bold;");
}else{
console.log(msg);
}
}
clog(123);
clog(123,'red');
| Format specifier | Description |
|---|---|
| %s | Formats the value as a string. |
| %d or %i | Formats the value as an integer. |
| %f | Formats the object 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 | Applies CSS style rules to output string specified by the second parameter. |