console.log()占位符用法-设置打印颜色

<!DOCTYPE html> 
<html lang="en"> 
    <head> 
        <meta charset="UTF-8" /> 
        <meta name="viewport" content="width=device-width,initial-scale=1.0" /> 
        <title>console Demo</title> 
    </head> 
    <style> 
        

    </style> 
    <body> 
       
    </body> 
    <script>
        
        
        //1、在实际中应用案例-百度招聘,此外,在项目调试的时候可以设置颜色,在控制台可以直接锁定输出位置
        console.log('%c百度2022校园招聘简历投递:%chttps://talent.baidu.com/external/baidu/campus.html','color:red','color:black')
        
        
        
        //2、%c占位符:指令后的文本将使用参数中的 CSS 声明进行样式设置
        console.log('%cthis is one console','color: red;')
        console.log('123%c456','color: red;')
        console.log('123%c456','color: red;font-size:28px;border:1px solid blue;')
        
        
        
        //3、动态数据设置方法-模板字符串
        var a=10
        console.log(`%c${a}`,'color:yellow')
        
        
        
        //4、%c占位符:多种颜色的设置
        console.log('%c123%c456%c789','color:pink','color: red;','color:green')
        
        
        
        //console 能够解析占位符
        //%s 字符串
        // %d %i整数
        // %f 浮点数
        // %o 对象的链接
        // %c CSS 格式字符串
        

        var number = 11 * 9
        var float = 10.98
        var color = 'red'
        console.log('%d %s console', number, color)
        console.log('%i %s console', number, color) 
        
        console.log('%i %s console', float, color) 
        console.log('%d %s console', float, color) 
        console.log('%f %s console', float, color)

        console.log(' %s + %s =2', 1, 1)
        
        console.log('%o',document.body);
        console.log('%O', document.body);



    </script>
</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值