如何设置-webkit-print-color-adjust:以编程方式与Javascript完全一样?



我需要使用 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 );

最新更新