javascript - 如何 console.log 多个对象?
问题描述
我正在创建一个 javascript 练习,我的想法是创建一个可以返回图标的函数,我为此使用了 FontAwesome。我设法让它显示图标和消息,但我想通过一个函数添加我预定义的标题、强调等样式,但我仍然想不出一个表单。我什至尝试使用 Swith 但它只将 css 复制为任何字符串
function icones(ico_name, text,style ){ // Capture icon name, style to be used and text
switch(ico_name) { //Check argument icon
case 'user':
ico_name = '%c ' //Icon will only be displayed after CSS declaration
font = 'font-family: "Font Awesome 5 Free"; font-weight: 900; font-size: 20px; content: "\f434";'
break
}
switch(style) { // Styling text
case 'title':
text = 'color: red'
break
}
console.log(ico_name,font,text)
}
icones('user','player', 'title') //Applying values to function
解决方案
经过几个小时的反复试验,我终于完成了我的壮举。“秘密”是在一个 console.log 中放置 2 种样式,代码可能看起来像是一个令人困惑的漂移,并且肯定会改进它。
function icones(ico_nome,texto,style ){ // Captura o nome do icone, o estilo que sera utilizado e o texto
switch(ico_nome) { // Check argument icon
case 'user':
ico_nome = '%c ' // Icon will only be displayed after CSS declaration
font_icon = 'font-family:"Font Awesome 5 Free"; font-weight: 900; font-size: 20px;' //Declara a fonte para visualização
break
}
switch(style) { // Styling text
case 'titulo': // Set styles for titles
font_icon += 'color:red;' //Set the color Red to Icon
style_text = 'color:blue; font-family: Arial;' // Set styles for texts
break
default:
font_icon += 'color: black' // Set default color
}
console.log(ico_nome + ' ' + '%c' + texto,font_icon,style_text) //Join the 2 styles and reveal the output
}
icones('user','Usuario', 'titulo') //Applying values to function
最终结果----控制台输出 还是不知道怎么把图片直接插入帖子里抱歉:)
推荐阅读
- assembly - 如何在汇编中初始化数组的大小和指向数组的指针?
- regex - IDA 搜索多条指令
- python - 从python中的前导零中只打印一个零
- cmake - Cmake 的 SET 会发生什么
- amazon-web-services - 在 AWS Route 53 中创建子域并在 WIX 上配置以路由子域请求
- .htaccess - htaccess 重写规则,带有数字作为子域名的一部分
- javascript - 只有第一个按钮有效。不确定它是否是脚本。可能是我错过了一条规则
- javascript - javascript P5函数创建无限循环
- react-native - Expo SplashScreen 独立构建失败
- elasticsearch - 增加 ElasticSearch 中的队列容量