中易网

js如何才能取到style的值?

答案:5  悬赏:30  
解决时间 2021-12-20 17:51
js如何才能取到style的值?
最佳答案
用jquery可以很轻松的取到了,比如:
<div id="divTest" style="height:100px"></div>
只需要:
$("div#divTest").css("height");就可以取到height的值了。
有用的话要采纳哟!
全部回答
var div = document.getElementById('amountDiv');          if (navigator.userAgent.indexOf("MSIE")>0)     { //IE                div.style.cssText = sty;           } else { //w3c             div.style = sty;            }
test
<script> alert(document.getelementbyid("e").style.color) alert(document.getelementbyid("e").style.fontsize) alert(document.getelementbyid("e").classname) </script>
&lt;div id=&quot;e&quot; style=&quot;color:red;font-size:14px&quot; class=&quot;c&quot;&gt;test&lt;/div&gt;<br>&lt;script&gt;<br>alert(document.getElementById(&quot;e&quot;).style.color)<br>alert(document.getElementById(&quot;e&quot;).style.fontSize)<br>alert(document.getElementById(&quot;e&quot;).className)<br>&lt;/script&gt;
楼下的都不靠谱!<br><br>&lt;script&gt;<br><br>elem=document.getElementById('btn');<br>str='';<br>if (elem.currentStyle){arr=elem.currentStyle;<br>    for(i in arr)<br>    str+=i+&quot;:&quot;+arr[i]+'\n'; }<br>  else if(document.defaultView&amp;&amp;document.defaultView.getComputedStyle) {<br>    arr=document.defaultView.getComputedStyle(elem,null);<br>    for(i in arr)<br>    str+=i+&quot;:&quot;+arr[i]+'\n';    }<br> alert(str);<br>&lt;/script&gt;<br>基本上就能遍历到所有的style 属性,而且就算不是内联的样式也可以得到数据!
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
闽侯世茂上游墅三期ab地块别墅值多少钱
钠盐是最易缺的盐吗?急啊,快谢谢了!
酌水的意思是什么?酌水的释义是什么啊?
跪求宇宙战舰大和2199百度云
按舞的意思是什么啊?请解释下!
1到100中是合数而不是偶数的有哪些
巽懦的意思是什么?巽懦的释义是什么啊?
包饺子剩下的皮怎么办?--------水果糖详细??
防范心理很强是不自信造成的吗?因为不自信会
大节夜的意思是什么啊?请解释下!
宁夏特岗小学计算机教师考试历年试题
找关于儿童的诗
跪求!!!!!!!!!!!!!!!20092010
出倒的意思是什么?出倒的释义是什么啊?
深圳市住房公积金中心宝安管理部地址在哪,我
推荐资讯
平价精品男装地址在什么地方,想过去办事
连枉的意思是什么啊?请解释下!
俚柔的意思是什么啊?请解释下!
如果我办了移动的亲情号码时间超出了资费怎么
LOL剑姬的的破绽是a到破绽上面就能打出来还是
新豪天地我想知道这个在什么地方
地下城歌颂者4000w值不值大神估价
RedHatEnterpriseLinux5文件权限的管理
送年的意思是什么?送年的释义是什么啊?
比亚迪s7仪表间接性黑屏是什么原因
求M5015linux阵列卡驱动
游戏里的名字怎么变成红的字了
手机登qq时,显示手机磁盘不足,清理后重新登
刺客的套装怎么选啊?