arguments(数组) 可变参/不定参
arguments.length
function sum(){
var results = 0;
for(var i = 0;i < arguments.length;i++)
results += arguments[i];
return results;
}
alert(sum(1,2,3,4,5));
-----------------------------------------
jq
css(oDiv,'width') 获取样式
css(oDiv,'width','200px') 设置样式
------------------------------------------
alert(currentStyle.width) 获取非行间样式//只兼容IE
alert(getComputedStyle(oDiv,null).width) 火狐
if(oDiv.currentStyle){
alert(currentStyle.width);
}
else{
alert(getComputedStyle(oDiv,null).width);
}
----------------------------------------------------
获取非行间样式//不能获取复合样式(background、border)
function getStyle(obj,name){
if(obj.currentStyle){
return obj.currentStyle[name];
}
else{
return getComputedStyle(obj,null)[name];
}
}
window.onload = function(){
var oDiv = document.getElementById('div1');
alert(getStyle(oDiv,'width'));
}
-----------------------------------------------------
数组
a = {1,2,3};
a = new array(1,2,3);
尾部添加 a.push(4);
尾部删除 a.pop();
头部添加 a.unshift(5);
头部删除 a.shift();
删除:a.splice(起点,长度);
插入:a.splice(起点,长度,元素...);
替换:a.splice(2,2,'a','b');
连接:
var a = {1,2,3};
var b = {4,5,6};
alert(a.contact(b))l
alert(a.join('-')); ----->1-2-3
排序
字符排序
var a = {'float','width','alpha','zoom','left'};
a.sort();
alert(a);
数字排序
var a = {12,8,99,19,112};
a.sort(function(n1,n2)){
return n1 - n2;
}
alert(a);
-----------------------------------------------------
js笔记(8)之数组篇
最新推荐文章于 2024-05-29 09:02:03 发布