JS设置css样式的几种方式

/* 1.直接设置style属性 */
element.style.height = '100px';
 
/* 2.直接设置属性 */
element.setAttribute('height', '100px');
 
/* 3.使用setAttribute设置style属性 */
element.setAttribute('style', 'height: 100px !important');
 
/* 4.使用setProperty设置属性,通过第三个参数设置important */
element.style.setProperty('height', '300px', 'important');
 
/* 5.设置cssText */
element.style.cssText += 'height: 100px !important';
原文地址:https://www.cnblogs.com/mengff/p/8073641.html