js 基础

来源:互联网 发布:淘宝秒杀系统繁忙 编辑:程序博客网 时间:2024/06/07 11:48
<!DOCTYPE html>
<html lang="en">
<head>
<!-- 
只能用于IE浏览器
Object.currentStyle.():获取非行内样式//只能用于IE可以获取默认样式和基本样式   不能获取复合样式


用于火狐,Chrome等浏览器
getComputedStyle(object,false).()


Object.style.()只能获取行内样式
 -->
<style type="text/css">
#div{width: 100px;height: 100px;background-color: #123456;}
</style>
<script type="text/javascript">


window.onload=function(){


oDiv=document.getElementById('div');


oBtn=document.getElementsByTagName('input')[0];


oBtn.onclick=css(oDiv,'width','200px');


function getStyle(oDiv,attr){
if(oDiv.currentStyle)
{alert(oDive.currentStyle[attr]) ;}
// {return oDive.currentStyle[attr];}
else
// {return getComputedStyle(oDive,false)[attr];}
{alert(getComputedStyle(oDiv,false)[attr]);}
}


function css(oDiv,attr,value){
    if(arguments.length==2)
    {getStyle(oDiv,attr);}
    else if(arguments.length==3)
    {oDiv.style[attr]=value;}
}
}
</script>
<meta charset="UTF-8">
<title>获取样式</title>
</head>
<body>
<input type="button" value="Change">
<div id="div"></div>
</body>
</html>
0 0