【问题标题】:How to set -webkit-print-color-adjust: exact from Javascript programmatically?如何以编程方式设置 -webkit-print-color-adjust:与 Javascript 完全一致?
【发布时间】:2020-02-03 04:40:30
【问题描述】:
我需要使用 Javascript 以编程方式设置以下 CSS 样式:
body {
-webkit-print-color-adjust: exact;
}
我遇到的问题是:
- 我不想删除body style的其他属性;我只想添加-webkit-print-color-adjust
- 我似乎无法使用 document.body.style,因为此特殊样式名称中的前导连字符
对此的任何帮助将不胜感激
【问题讨论】:
标签:
javascript
html
css
styles
【解决方案1】:
let body = document.querySelector('body');
body.style.setProperty('-webkit-print-color-adjust', 'exact');
// check how the style is now present in the DOM ( it is the "webkitPrintColorAdjust" property)
console.log( body.style );