1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
<!DOCTYPE HTML> <html lang= "zh-cn" >
<head> <meta charset= "utf-8"
/>
<meta http-equiv= "Content-Language"
content= "zh-cn"
/>
<title>css函数</title> <meta name= "keywords"
content= ""
/>
<meta name= "description"
content= ""
/>
<style type= "text/css" >
*{ margin: 0px; padding: 0px; font-size:14px; font-family: ‘微软雅黑‘ ;
} .clearfix:after{content: ‘.‘ ;display:block;height:0;clear:both;visibility:hidden}
.clearfix{display:inline-block;} * html .clearfix{height:1%} .clearfix{display:black;} ul li{ list-style:none;font-size:14px; height:20px; line-height:20px; width:320px;
} ul li. new {
color:red;
} </style> </head> <body> <script type= "text/javascript" >
window.onload = function(){ var
oBox = $( ‘box‘ );
var
oLi = oBox.getElementsByTagName( ‘li‘ );
for ( var
i=0;i<oLi.length;i++){
css(oLi[i], ‘color‘ , ‘red‘ );
}
alert(css(oLi[0], ‘fontSize‘ ));
} function css(obj,name,value){ if (arguments.length == 2){
if (obj.currentStyle){
return
obj.currentStyle[name];
} else {
return
getComputedStyle(obj, false )[name];
}
} else {
return
obj.style[name] = value;
};
} function $(id){ return
document.getElementById(id);
} </script> <ul id= ‘box‘ >
<li>三国卫星拍到疑似失联客机漂浮物 搜寻无实质进展</li>
<li>美媒:失联客机曾急转掉头并降低飞行高度</li>
<li>马来西亚警方追查与失联客机机长通话神秘女人</li>
<li>*警方强行驱离示威民众 75人被逮捕</li>
<li>**现场:警方持盾牌推进 民众血流满面</li>
<li>平度征地血案续:村委会被指伪造村民签名卖地</li>
<li>山西致31死爆炸事故目击交警被约谈后坠亡</li>
<li>中宣部原副部长:必须彻底清算*思维</li>
</ul> </body> </html> |
arguments来判断传入参数的的个数
currentStyle IE下获取元素的最终样式
getComputedStyle 火狐获取下元素的最终样式