1.获取内联样式
element.style.attr
2.获取css内部样式
<!DOCTYPE html> <html> <head> <title></title> <style type="text/css"> div{ width: 100px; height: 100px; background: red; } </style> </head> <body> <div ></div> <script type="text/javascript"> function getStyle(element , attr) { //currentStyle仅支持IE return element.currentStyle ? element.currentStyle['attr'] : getComputedStyle(element)[attr]; } var div = document.getElementById('div'); div.onclick = function () { // console.log(document.defaultView.getComputedStyle(div).height); console.log(getStyle(div,'height')); } </script> </body> </html>
版权声明:除特别声明外,本站所有文章皆是本站原创,转载请以超链接形式注明出处!