[JS]视频总结-第三部分_深入javascript

08.javascript基础 - 1

 <!doctype html> <html> <head> <meta charset="utf-8"> <title>08-不定参-获取/设置行间/非行间样式-数组</title> </head> <style> /*非行间样式*/ #div1 {200px; height:400px; background:red;} </style> <script> function setupCss(obj, name, value){ if(arguments.length==2) { return obj.style[name]; }else { obj.style[name]=value; } } function getStyle(obj, name){ if(obj.currentStyle) { //IE return obj.currentStyle[name]; } else { //FF return getComputedStyle(obj, false)[name]; } } window.onload=function(){ var di1=document.getElementById('div1'); //alert(setupCss(di1, 'width')); //setupCss(di1, 'height', '600px'); //alert(setupCss(di1, 'height')); //取非行间样式 //alert(di1.currentStyle.height);//高板IE,Chrome支持 //避免兼容性问题采用以下方式 //alert(getComputedStyle(di1, null).width); /*if(di1.currentStyle) { //IE alert(di1.currentStyle.height); } else { //FF alert(getComputedStyle(di1, null).width); }*/ //alert(getStyle(di1, 'height')); //复合样式-background,border... //但一样式-color,height... //alert(getStyle(di1, 'backgroundColor')); //数组 var a=[1, 2, 3, 4, 5, 6]; alert(a.length); //a.length=4; alert(a);//1,2,3,4 //数组的添加-尾部 a.push(7); alert(a); //头部添加 a.unshift(8); alert(a); //删除-尾部开始 a.pop(); alert(a); //从头部开始删除 a.shift(); alert(a); //从中间添加/删除 var b=[11, 12, 13, 14, 15]; //splice(起点,长度)-删除 b.splice(2, 2); alert(b); //插入 var c=[21, 22, 23, 24]; c.splice(2, 0, 'a', 'b', 'c'); alert(c); //替换 var d=[31, 32, 33, 34]; c.splice(2, 2, 'a', 'b'); alert(c); //数组的连接 var d=[1, 2, 3, 4]; var e=['a', 'e', 'c', 'f']; alert(d.concat(e)); //连接符 alert(e.join('-+-~')); //排序 var f=['sdf', 'we', 'wer', 'ngf', 'hyj']; alert(f.sort()); //实际排序 var g=[12, 43, 10, 1189, 234, 72]; alert(g.sort()); alert(g.sort(function(n1, n2) { if(n1<n2) { return -1; }else if(n1>n2) { return 1; }else { return 0; } //return n1-n2; })); } </script> <body> <!-- 行间样式 --> <div id="div1"> </div> </body> </html>   

 

原文地址:https://www.cnblogs.com/webapplee/p/3771680.html