今天学习了获取行间样式和非行间样式,
解决不同浏览器的兼容性问题,
很多兼容性问题都可以通过if(){}else{}解决
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>qufeihangjianyangshi</title>
<style>
#div1 {
width: 200px;
height: 200px;
background: red;
}
</style>
<script>
function getStyle(obj,name){
if(obj.currentStyle){
return obj.currentStyle[name]; //IE
}else{
return getComputedStyle(obj,false)[name]; //chrome firefox
}
}
window.onload = function () {
var oDiv = document.getElementById('div1');
alert(getStyle(oDiv,'width'));
}
</script>
</head>
<body>
<div id="div1"></div>
</body>
</html>