标签:tle html col argument 数字 char none name val
1.函数传参
<!DOCTYPE HTML> <html> <head> <meta charset="utf-8"> <title>无标题文档</title> <script> function sum() { //alert(arguments.length); //alert(arguments[0]); //arguments var result=0; for(var i=0;i<arguments.length;i++) { result+=arguments[i]; } return result; } alert(sum(12, 6, 8, 6, 8, 6, 8, 6, 8, 6, 8, 6, 8, 6, 8, 6, 8, 6, 8, 6)); </script> </head> <body> </body> </html>
<!DOCTYPE HTML> <html> <head> <meta charset="utf-8"> <title>无标题文档</title> <script> function css(obj, name, value) { if(arguments.length==2) //获取 { return obj.style[name]; } else //设置 { obj.style[name]=value; } } window.onload=function () { var oDiv=document.getElementById(‘div1‘); alert(css(oDiv, ‘width‘)); //css(oDiv, ‘background‘, ‘green‘); }; </script> </head> <body> <div id="div1" style="width:200px; height:200px; background:red;"> </div> </body> </html>
2.取非行间样式:
取非行间样式(不能用来设置):
<!DOCTYPE HTML> <html> <head> <meta charset="utf-8"> <title>无标题文档</title> <style> #div1 {width:200px; height:200px; background:red;} </style> <script> function getStyle(obj, name) { if(obj.currentStyle) //IE { return obj.currentStyle[name]; } else //chrome / FF { return getComputedStyle(obj, false)[name]; } } window.onload=function () { var oDiv=document.getElementById(‘div1‘); alert(getStyle(oDiv, ‘backgroundColor‘)); }; </script> </head> <body> <div id="div1"> </div> </body> </html>
但是要注意上面getStyle()存在的问题,这个只能取单一样式,如果要取复合样式,如上面的background,要使用‘backgroundColor‘
3.数组基础
1)添加、删除元素
2)插入、删除
<script> var arr=[1,2,3,4,5,6]; //删除:splice(起点, 长度) //arr.splice(2, 3); //插入:splice(起点, 长度, 元素...); //arr.splice(2, 0, ‘a‘, ‘b‘, ‘c‘); arr.splice(2, 2, ‘a‘, ‘b‘); alert(arr); </script>
3)排序、转换
<script> var arr=[‘float‘, ‘width‘, ‘alpha‘, ‘zoom‘, ‘left‘]; arr.sort(); alert(arr); </script>
<script> var arr=[12, 8, 99, 19, 112]; arr.sort(function (n1, n2){ return n1-n2; /*if(n1<n2) { return -1; } else if(n1>n2) { return 1; } else { return 0; }*/ }); alert(arr); </script>
4.
标签:tle html col argument 数字 char none name val
原文地址:http://www.cnblogs.com/tenWood/p/7668966.html