前端通过JS获取和设置样式
获取样式:
方式一:style 仅能获取元素的内联样式
ele.style.width // ele.style.height // ele.style.cssText // ele.style.getPropertyValue('background-color')
方式二:getComputedStyle 获取元素的计算样式(最终表现出来的样式)
getComputedStyle(ele).cssText // getComputedStyle(ele).getPropertyValue('background-color')
设置样式:
ele.style.width='100px';
ele.style.cssText='width : 200px; height:300px; border:1px solid #fff; ';
浙公网安备 33010602011771号