获取css变量 getComputedStyle(document.documentElement) .getPropertyValue('--primary-color'); 设置css变量 document.body.setProperty('--primary-color','#fff'); 获取伪类元素 var dom = getComputedStyle(document.body, '::before');