我需要使用 Javascript 以编程方式设置以下 CSS 样式:
body {
-webkit-print-color-adjust: exact;
}
我遇到的问题是:
- 我不想删除正文样式上的其他属性;我只想添加 -webkit-print-color-adjust
- 由于这种特殊样式名称中的前导连字符,我似乎无法使用 document.body.style
对此的任何帮助将不胜感激
最佳答案
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 );
关于javascript - 如何设置-webkit-print-color-adjust : exact from Javascript programmatically?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60033170/