javascript-对文档对象的内容、属性、样式的操作(下)
时间:2014-09-27 点击:次
javascript-对文档对象的内容、属性、样式的操作(下)
一、css层叠样式的操作
1>通过ID来更改样式
2>通过className更改样式
*******************************************
适合批量更改
*******************************************
3>更改或者获取或者设置某个属性的值
**************************************************************
document.styleSheets[下标].rules[下标].style.属性
document.styleSheets[下标].rules[下标].style.属性=值
document.styleSheets 样式表的集合
document.styleSheets[0].rules 样式规则的列表
document.styleSheets[0].rules.style 样式规则的集合
document.styleSheets[下标].rules[下标].style.属性
适用于IE
**************************************************************
document.styleSheets[下标].cssRules[下标].style.属性
document.styleSheets[下标].cssRules[下标].style.属性=值
适用于FF
***************************************************************
4> 动态的添加删除css样式规则
document.styleSheets[下标].insertRule("选择器{属性:值}",位置) FF w3c
deleteRule(位置) FF w3c
document.styleSheets[下标].addRule("选择器","属性:值",位置) IE removeRule(位置) IE
二、行内样式和css层叠样式通用的方式
对象.currentStyle.属性 IE 用来获得实际的样式属性
getComputedStyle(对象,null) FF 用来获得实际的样式属性
*******************************
只能获取不能设置
*******************************
一、css层叠样式的操作
1>通过ID来更改样式
2>通过className更改样式
*******************************************
适合批量更改
*******************************************
3>更改或者获取或者设置某个属性的值
**************************************************************
document.styleSheets[下标].rules[下标].style.属性
document.styleSheets[下标].rules[下标].style.属性=值
document.styleSheets 样式表的集合
document.styleSheets[0].rules 样式规则的列表
document.styleSheets[0].rules.style 样式规则的集合
document.styleSheets[下标].rules[下标].style.属性
适用于IE
**************************************************************
document.styleSheets[下标].cssRules[下标].style.属性
document.styleSheets[下标].cssRules[下标].style.属性=值
适用于FF
***************************************************************
4> 动态的添加删除css样式规则
document.styleSheets[下标].insertRule("选择器{属性:值}",位置) FF w3c
deleteRule(位置) FF w3c
document.styleSheets[下标].addRule("选择器","属性:值",位置) IE removeRule(位置) IE
二、行内样式和css层叠样式通用的方式
对象.currentStyle.属性 IE 用来获得实际的样式属性
getComputedStyle(对象,null) FF 用来获得实际的样式属性
*******************************
只能获取不能设置
*******************************