1 // return 没给值或者bureturn 都会返回 undefine
2 function show()
3 {
4 return ;
5 }
6
7 alert(show());
1 //函数传参 arguments用法 理论上可以传任意个参数 一般使用数组
2 function sum()
3 {
4 var result=0;
5 var i=0;
6
7 for(i=0;i<arguments.length;i++)
8 {
9 result+=arguments[i];
10 }
11
12
alert(result);
13 }
14
15 sum(12, 5, 7, 8, 12, 5, 7, 8, 12, 5, 7, 8, 12, 5, 7, 8, 12, 5, 7, 8, 12, 5, 7, 8, 12, 5, 7, 8, 12);
1 function getStyle(obj, attr)
2 {
3 if(obj.currentStyle)
4 {
5 return obj.currentStyle[attr];
6 }
7 else
8 {
9 return getComputedStyle(obj, false)[attr];
10 }
11 }
12
13 function css()
14 {
15 if(arguments.length==2) //获取
16 {
17 return getStyle(arguments[0], arguments[1]);
18 }
19 else if(arguments.length==3) //设置
20 {
21 arguments[0].style[arguments[1]]=arguments[2];
22 }
23 }
24
25 window.onload=function ()
26 {
27 var oBtn=document.getElementById('btn1');
28 var oDiv=document.getElementById('div1');
29
30 oBtn.onclick=function ()
31 {
32 //css(oDiv, 'background', 'green');
33 //alert(oDiv.style.width); 无法获取,只能获取行内样式
34 //alert(oDiv.currentStyle.width); 获取计算后的样式(当前样式/最终样式) 可以取到任何地方的样式
35 //currentStyle 支持IE 不支持火狐
36 //getComputedStyle(oDiv,false).width; 支持火狐 不支持IE
37 alert(css(oDiv, 'width'));
38 }
39 }
40 </script>
41
42
43 <input id="btn1" type="button" value="样式"/>
44 <div id="div1">
45
46 </div>