图片中,元素同时设置了内联样式和style
假设我们想获取class="s_btn"的按钮的width属性设置的值,改怎么获取呢?
1.获取内联样式width:
document.querySelector('.s_btn').style.width
2.如果既有内联样式又设置了style属性,想获取dom元素真实生效的width时
document.querySelector('.s_btn').computedStyleMap().get('width').value;
当dom元素没有设置内联样式和style属性时,computedStyleMap()方法的结果为auto
不考虑样式,直接获取dom元素的实际宽度:
window.getComputedStyle(document.querySelector('.tag-select_3Yje6')).width
window.getComputedStyle(dom).width在无边框情况下等同于dom.clientWidth