1 <!DOCTYPE html> 2 <html> 3 <head> 4 <meta charset="utf-8"> 5 <meta name="viewport" content="width=device-width"> 6 <title>获取对象属性</title> 7 </head> 8 <body> 9 <div class="odiv" id="odiv">abc</div> 10 <script> 11 var odiv=document.getElementById("odiv"); 12 function getStyle(obj){ 13 this.obj=obj; 14 this.attr= this.obj.currentStyle? this.obj.currentStyle:getComputedStyle(this.obj,null); 15 } 16 var odiv_s = new getStyle(odiv); 17 var ab = odiv_s.attr.color; 18 alert("odiv对象的颜色属性值为"+ab); 19 </script> 20 </body> 21 </html>