js 增加样式
document.getElementById('div4').style.height = '100px';
js 获取div的高度
普通:(内联元素有高度)
<div id="div4" style="height:100px"></div>
let height = document.getElementById('div4').style.height;
高级:(内联元素无高度)
<div id="div4"></div>
let div = document.getElementById('div4');
let hei = window.getComputedStyle(div).getPropertyValue('height')
window.getComputedStyle() 方法获取的是最终应用在元素上的所有CSS属性对象;
getPropertyValue() 方法可以获取CSS样式申明对象上的属性值;
style 属性只能获取内联样式;