获取页面、可视区域、容器本身高度宽度 1,获取页面的高度宽度var sHeight=document.documentElement.scrollHeight;var sWidth=document.documentElement.scrollWidth;2,获取可视区域的高度宽度var cHeight=document.documentElement.clientHeight;var cWidth=documen
children--- 只读属性---子节点列表集合 元素.children : 只读 属性 子节点列表集合 标准下:只包含元素类型的节点 非标准下:只包含元素类型的节点元素.children兼容好,常用!!!元素.childNodes : 只读 属性 子节点列表集合 标准下:包含文本和元素类型的节点,也会包含非法嵌套的子节点 非标准下:只包含元素类型的节
concat(),reverse(),字符串取反 concat():var arr1=[1,2,3,4];var arr2=['marie','tony'];var arr3=['safe','sound'];alert(arr1.concat(arr2,arr3))reverse():var arr1=[1,2,3,4,55,4,33,22];alert(arr1.reverse())字符串取反:先通过s
ceil()向上取整与round()逢五进一 取1~5随机数的两种方法:Math.ceil(Math.random()*5)Math.round(Math.random()*(5-1)+1)alert(Math.round(Math.random()*(y-x)+x)); //x~yalert(Math.round(Math.random()*80+20))//20~100alert(Math.round(Math
数组排序sort()用法 1.字符串排序var arr=['a','b','a','f','e'];arr.sort();alert(arr); 2.数字排序var arr=[3,1,9,4,87]arr.sort();arr.sort(function(x,y){return x-y;})alert(arr)3.带字符的数字大小排序var arr=['34px','345
1种数组去重的方法 var arr=[1,2,3,1,4,5,1];for(var i=0;ifor(var j=i+1;jif(arr[i]==arr[j]){arr.splice(j,1);j--;}}}alert(arr)
数组中的splice() splice(index,num,string)删除:var arr=['smile',2,3,'marie'];arr.splice(0,2) //从第一个值(0)开始删除该数据的两(2)个值alert(arr.splice(0,2)) //返回 smile,2alert(arr) //返回3,marie修改:var arr=['smile',2,3,'
数组的4个方法 应用arr.push(arr.shift())alert(arr) //返回 2,3,marie,smilearr.unshift(arr.pop())alert(arr) //返回 marie,smile,2,3
数组的length属性可读可写,字符串的长度length属性不可以修改 数组的length属性可读可写,字符串的长度length属性不可以修改清空数组的两种方法:arr.length=0;arr=[];
遍历对象 var str='';var num=1;for(var attr in document){ //window or document objectstr+=num+'. '+attr+':'+document[attr]+'';num++;}document.body.innerHTML=str;
str.charCodeAt()与String.fromCharCode()用法 str='123';str.charCodeAt(0)=48;str的值为0~9str.charCodeAt(i)的值为48~57str的值为a~zstr.charCodeAt(i)的值为97~122str的值为A~Zstr.charCodeAt(i)的值为65~90String.fromCharCode(48, 49)=01st
封装好的运动方法 function move(obj,val,target,dir,endFn){val=parseInt(getStyle(obj,dir))clearInterval(obj.timer);obj.timer=setInterval(function(){var speed=parseInt(getStyle(obj,dir))+val;if(speed>=target&&v
获取样式方法 function getStyle(obj,sty){return obj.currentStyle?obj.currentStyle[sty]:getComputedStyle(obj)[sty];}
函数调用参数判断 function fn1(a){if(typeof a==='number' && a===a) //a是数字且不是NaN{alert(a+8);}else if(typeof a==='string'){alert(a.charAt(3));}else if(typeof a==='function'){a();}}fn1(100);fn1('mari
parseFloat(c)==parseInt(c)小应用 var c='209.87';if(parseFloat(c)==parseInt(c)){alert(c+'是整数!');}else{alert(c+'是浮点数!');}
修改ul下li下的ul下的li的css样式 修改ul下的ul下的li的css样式window.onload=function(){var oUl=document.getElementById('list');var arrUl=oUl.getElementsByTagName('ul');var ulLen=arrUl.length;var arrLi=null;for(var i=0;iarrLi=arr
二维数组中的for循环 二维数组中的for循环window.onload=function(){var arr=[['tony','jenny','marie','nal'],[1,2,3,4,5],['aa','bb','cc','dd']];var len=arr.length;for(var i=0;ivar sLen=arr[i].length;for(var j=0;jaler
js中[]与.用法 js中[]与.用法*{margin: 0;padding: 0;}html,body{width: 100%;height: 100%;overflow: hidden;}.wrap{width: 100%;height: 100%;padding: 100px;background: darkgrey;color: white;
三列布局中间自适应的3种写法 定位法:*{margin: 0;padding: 0;}html,body{height: 100%;margin: 0;}.ll,.rr{position: absolute;top: 0;width: 200px;height: 100%;background: hotpink;}.ll{left: 0
each中的this each中的this$(function(){$('li').each(function(i,elem){/*console.log(i);console.log(elem);*/console.log(this); //this=elem$(this).html(i);if(i==4){return false;}})})