- 样式的位置
- 行内样式:通过html标签的style属性操作
- 元素.style.xxx样式
- 非行内样式
- 正常浏览器:getComputedStyle(元素).xxx样式
- 低版本IE:元素.currentStyle.xxx样式
- 行内样式:通过html标签的style属性操作
- 操作方式
- 获取
- 非行内样式获取(既能获取非行内,又能获取行内)
- 设置:
- 设置指定值
- 行内样式设置(高权重保证样式的生效)
- 清空(重置)样式
- 背景色,清空:如:background: “”;
- 字体大小,重置:如:font-size: 16px;
- 设置指定值
- 获取
- 获取样式找非行内操作
- 设置样式找行内操作
- 获取非行内样式的兼容封装
function getStyle(ele, cssName) {
if (ele.currentStyle) {
return (ele.currentStyle[cssName]);
} else {
return (getComputedStyle(ele)[cssName]);
}
}