<!--DOCTYPE
html-->
<html>
<head>
<meta
charset=
"utf-8"
/>
<style>
*{
text-align:center;}
input{
margin-top:30px; padding:10px 20px;}
#div1{
width:500px; height:300px; background:red; margin:10px auto;}
</style>
</head>
<body>
<input
type=
"button"
value=
"style"
id=
"btn"
/>
<div
id=
"div1"
></div>
<script>
function
getStyle(obj,attr){
if
(obj.currentStyle){
return
obj.currentStyle[attr];
}
else
{
return
getComputedStyle(obj,
false
)[attr];
};
};
function
css(obj,attr,value){
if
(arguments.length
== 2){
return
getStyle(obj,attr);
}
else
{
if
(arguments.length
== 3){
obj.style[attr]
= value;
};
};
};
window.onload
= function(){
var
oDiv
= document.getElementById(
"div1"
);
var
oBtn
= document.getElementById(
"btn"
);
oBtn.onclick
= function(){
alert(getStyle(oDiv,
"height"
));
css(oDiv,
"background"
,
"green"
);
alert(css(oDiv,
"width"
));
};
};
</script>
</body>
</html>