<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Untitled Document</title>
<style>
#div1 {width:200px; heigth:200px; background:red;}
</style>
<script>
/*
css中有两种样式
1.复合样式:background,border
2.单一样式:width,height,等
*/
//获取样式,没有办法取得复合样式兼容IE,FF
function getStyle(obj,name)
{
if(obj.currentStyle)
return obj.currentStyle[name];
else
return getComputedStyle(obj,false)[name];
}
window.onload = function (){
var oDiv=document.getElementById('div1');
alert(getStyle(oDiv,'width'))
alert(getStyle(oDiv,'backgroundColor'))
}
</script>
</head>
<body>
<div id="div1">
</div>
</body>
</html>
js获得样式兼容IE,FF等
最新推荐文章于 2021-07-17 15:12:06 发布