0
点赞
收藏
分享

微信扫一扫

添加样式

一只1994 2022-07-27 阅读 58

将提供的样式添加到给定元素。

使用 ​​Object.assign()​​​ 和 ​​ElementCSSInlineStyle.style​​​ 将提供的 ​​styles​​ 对象合并到给定元素的样式中。

const addStyles = (el, styles) => Object.assign(el.style, styles)
addStyles(document.getElementById('my-element'), {
background: 'red',
color: '#ffff00',
fontSize: '3rem'
})

举报

相关推荐

0 条评论