js中关于style,currenStyle,和getComputedStyle的区别
来源:互联网 发布:淘宝摄影接单 编辑:程序博客网 时间:2024/05/22 19:00
今天在学习js的时候,遇到了一个关于style的小问题,通过查阅相关资料,发现如下问题:
style获取的元素样式只能是内联样式。内部样式,就是本页面中<style></style>中的样式,style取不到;外部样式更不用说,也是取不到。
currentStyle可以取到,但是只有IE能用。
getComputedStyle和currentStyle作用是一样的,但支持的浏览器不同。
所以,可以写一个函数来兼容不同的浏览器;例如
function getStyle(obj,name){
if(obj.currentStyle){
return obj.currentStyle[name]
}else{
return getComputedStyle(obj,null)[name];
}
}
1 0
- js中关于style,currenStyle,和getComputedStyle的区别
- js中style,currentStyle和getComputedStyle的区别
- js中style,currentStyle和getComputedStyle的区别
- JS中style、currentStyle、getComputedStyle的区别
- JS中style、currentStyle、getComputedStyle的区别
- js中getComputedStyle 和currentStyle 的区别
- style,currentStyle,getComputedStyle的区别和用法
- style currentStyle getComputedStyle的区别和用法
- js获取css值的方法:style、getComputedStyle和currentStyle
- js获取css值的方法:style、getComputedStyle和currentStyle
- js获取css值的方法:style、getComputedStyle和currentStyle
- 论style、getComputedStyle、currentStyle之间的区别和联系
- Js中的style,currentStyle,getComputedStyle()区别
- CSS:getComputedStyle与style的区别
- JS中style.display和style.visibility的区别
- JS中style.display和style.visibility的区别
- JS中style.display和style.visibility之间的区别
- JS中style.display和style.visibility的区别
- ORA-01861_文字与格式字符串不匹配
- 第一周:PageRank学习心得--JAVA编程实现
- mahout分类学习和遇到的问题总结
- C# 通过 ManagementClass 获取本机IP 地址 报错
- Android-Parcelable理解与使用(对象序列化)
- js中关于style,currenStyle,和getComputedStyle的区别
- android之Intent复杂数据的传递(ArrayList<String>类型的数据)
- meta
- 黑马程序员 - 学习笔记1 重载方法
- 开通博客,欢迎来交流
- 系统权限数据库设计方案
- 10.4 UIScrollview概念和用法:单张图片缩放
- 你知道这些程序出现这些结果的原因吗?
- 【IPV6基础知识】IPV6邻居发现协议