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';
posted @ 2017-12-20 14:39  全玉  阅读(12358)  评论(0编辑  收藏  举报