<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml">
<wml>
<head><meta forua="true" http-equiv="Cache-Control" content="max-age=0" /></head>
<card title="js使用document.defaultView.getComputedStyle()、currentStyle()方法获取CSS属性值" id="card1">
<p> 游客</p><p>
标题:js使用document.defaultView.getComputedStyle()、currentStyle()方法获取CSS属性值<br/>
正文:<br/>
在对网页进行调试的过程中，经常会用到js来获取元素的CSS样式，方法有很多很多，现在仅把我经常用的方法总结如下： <br/><br/>1. obj.style：这个方法只能JS只能获取写在html标签中的写在style属性中的值（style=”…”），而无法获取定义在&amp;lt;style type=&quot;text/css&quot;&amp;gt;里面的属性。 <br/>代码如下:<br/>&amp;lt;span style=&quot;font-family:Arial;font-size:14px;&quot;&amp;gt;&amp;lt;!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “TR/xhtml1/DTD/xhtml1-transitional.dtd“&amp;gt; <br/>&amp;lt;html xmlns=”http://www.w3.org/1999/xhtml“&amp;gt; <br/>&amp;lt;head&amp;gt; <br/>&amp;lt;meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″ /&amp;gt; <br/>&amp;lt;title&amp;gt;JS获取CSS属性值&amp;lt;/title&amp;gt; <br/>&amp;lt;style type=”text/css”&amp;gt; <br/>&amp;lt;!– <br/>.ss{color:#cdcdcd;} <br/>–&amp;gt; <br/>&amp;lt;/style&amp;gt; <br/>&amp;lt;/head&amp;gt; <br/><br/>&amp;lt;body&amp;gt; <br/>&amp;lt;div id=”css88″ class=”ss” style=”width:200px; height:200px; background:#333333″&amp;gt;JS获取CSS属性值&amp;lt;/div&amp;gt; <br/>&amp;lt;script type=”text/javascript”&amp;gt; <br/>alert(document.getElementById(“css88″).style.width);//200px <br/>alert(document.getElementById(“css88″).style.color);//空白 <br/>&amp;lt;/script&amp;gt; <br/><a href="http://camnpr.com/wap.asp?mode=WAP&amp;act=View&amp;id=1193&amp;Page=1">[&lt;&lt;]</a><a href="http://camnpr.com/wap.asp?mode=WAP&amp;act=View&amp;id=1193&amp;Page=1">[[1]]</a><a href="http://camnpr.com/wap.asp?mode=WAP&amp;act=View&amp;id=1193&amp;Page=2">[2]</a><a href="http://camnpr.com/wap.asp?mode=WAP&amp;act=View&amp;id=1193&amp;Page=3">[3]</a><a href="http://camnpr.com/wap.asp?mode=WAP&amp;act=View&amp;id=1193&amp;Page=4">[&gt;&gt;]</a><br/>
<br/>
<a href="wap.asp?act=Com&amp;id=1193">查看评论(0)</a><br/>
<a href="wap.asp?act=AddCom&amp;inpId=1193">发表评论</a><br/><br/>

<br/>

<br/>
<a href="http://camnpr.com/wap.asp">首页</a>
</p>
</card>
</wml>