在完成公司项目时需要去动态计算高度然后设置给元素,但是由于项目本身已经书写过样式,导致设置的样式权重不够需要添加important来增加权重,在这个过程中发现:
// 可以生效
dom.style.height = '60px'
// 无法生效
dom.style.height = '60px !important'
在网上查阅后并实践后发现以下方式可行:
dom.style.setProperty('height', '60px', 'important')
在完成公司项目时需要去动态计算高度然后设置给元素,但是由于项目本身已经书写过样式,导致设置的样式权重不够需要添加important来增加权重,在这个过程中发现:
// 可以生效
dom.style.height = '60px'
// 无法生效
dom.style.height = '60px !important'
在网上查阅后并实践后发现以下方式可行:
dom.style.setProperty('height', '60px', 'important')