1 <!DOCTYPE html>
2 <html>
3 <head>
4 <meta charset="UTF-8">
5 <title>获取样式方法</title>
6 <style>
7 /*#div1{
8 width: 200px;
9 height: 200px;
10 background: red;
11 }*/
12 </style>
13 </head>
14 <body>
15 <div id="div1" style="width: 200px;height: 200px;background: red;"></div>
16 <script>
17 var oDiv = document.getElementById('div1');
18 // alert(css(oDiv,'width'));
19 // css(oDiv,'background','green');
20
21
22 // 1.使用arguments
23 // function css(){
24 // if(arguments.length == 2){ //获取
25 // return arguments[0].style[arguments[1]];
26 // }else{
27 // arguments[0].style[arguments[1]] = arguments[2];
28 // }
29 // }
30
31 // 2.使用对象传参
32 function css(obj,name,value){
33 if(arguments.length == 2){ //获取
34 return obj.style[name];
35 }else{
36 obj.style[name] = value;
37 }
38 }
39
40
41 </script>
42 </body>
43 </html>