style、currentStyle、getComputedStyle的应用
来源:互联网 发布:电脑录音软件 编辑:程序博客网 时间:2024/05/16 12:17
<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><title>style,currentStyle,getComputedStyle</title><style type="text/css">#div1 {background-color: #f60;width: 400px;height: 200px;margin: 0 auto;}</style><link rel="stylesheet" href="t.css"></head><body><div id="div1" style="padding:5px;color:#fff"></div><script type="text/javascript">function css(obj, attr) {if (obj.currentStyle) {//只在IE下有效,无论是元素的内联样式、外部样式,内部样式下都有效return alert("IE " + obj.currentStyle[attr]);} else {//2种情况:1:访问元素的内联样式,FF下没效果,chrome下有效果。// 2:访问内部样式和外部样式时,FF,chrome下有效果。return alert("FF,Chrome " + getComputedStyle(obj, false)[attr]);//2种情况:1:在访问元素的内联样式时,在IE,FF,chrome下均有效(返回颜色时返回的是rgb格式)// 2:在访问内部样式和外部样式时,会弹出窗口但不会有结果,在IE,FF,chrome下一样的情况//return alert("元素的内链样式:"+obj.style[attr]);}}css(div1, "width");</script></body></html>
t.css
#div1{cursor: pointer;}
这三种方法在浏览器兼容性方面相互互补,在元素访问的权限上主要体现在obj.style上。
0 0
- style、currentStyle、getComputedStyle的应用
- currentStyle和getComputedStyle的应用
- style,currentStyle,getComputedStyle的区别和用法
- javascript的样式获取--getComputedStyle、currentStyle、style
- 验证style,currentStyle以及getComputedStyle的兼容性。
- JS中style、currentStyle、getComputedStyle的区别
- JS中style、currentStyle、getComputedStyle的区别
- style currentStyle getComputedStyle的区别和用法
- style currentStyle getComputedStyle
- getcomputedstyle、currentStyle、style
- currentStyle,runtimeStyle,getComputedStyle style
- style、currentStyle、getComputedStyle区别介绍
- style、currentStyle、getComputedStyle区别介绍
- style、currentStyle、getComputedStyle区别介绍
- style、currentStyle、getComputedStyle区别介绍
- style、currentStyle、getComputedStyle区别介绍
- style、currentStyle、getComputedStyle区别介绍
- style、currentStyle、getComputedStyle区别介绍
- leetcode 012 Integer to Roman
- cxf生成客户端代码
- Python Appium实现中文输入分享
- phpmailer使用教程及实例演示
- LeetCode——Rectangle Area
- style、currentStyle、getComputedStyle的应用
- LIBRARY_PATH和LD_LIBRARY_PATH环境变量的区别
- ajax简单入门
- 使用指针取得Color的RGB值和透明度值
- java面向对象-this
- 编外的编外话
- OpenWrt的用处
- Sublime2 运行NodeJS
- eclipse最有用快捷键整理