JavaScript如何获取一个元素的样式信息
跨浏览器方法
functiongetStyle(elem,cssprop,cssprop2){
if(elem.currentStyle){
returnelem.currentStyle[cssprop]
}elseif(document.defaultView&&document.defaultView.getComputedStyle){
returndocument.defaultView.getComputedStyle(elem,"").getPropertyValue(cssprop2)
}else{
returnnull
}
}
getStyle取值的优先级是:
1.动态设置的
2.内联设置的
3.样式表设置的
4.浏览器默认设置的
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持毛票票。
热门推荐
10 广西考试祝福语结婚简短
11 猪年祝福语简短小孩
12 元旦祝福语送长辈简短
13 恭喜二宝祝福语简短
14 祝福语暖心话简短
15 国庆中秋祝福语简短兄弟
16 朋友订婚的祝福语简短
17 送弟弟中秋祝福语简短
18 爱生日祝福语简短独特