几个常用的Javascript函数

2008-02-23 07:52:12来源:互联网 阅读 ()

新老客户大回馈,云服务器低至5折

// *******************************************************
// replacements for unsupported array functions (because arrayname.push(var)
// and arrayname.pop() are not implemented in IE until version 5.5)
function thearrayisgood(thearray,i) {
if ((thearray[i] == "undefined") || (thearray[i] == "") || (thearray[i] == null))
return false;
else
return true;
}

function getarraysize(thearray) {
// replacement for arrayname.length property
for (i = 0; i < thearray.length; i ) {
if ((thearray[i] == "undefined") || (thearray[i] == "") || (thearray[i] == null))
return i;
}
return thearray.length;
}

function arraypush(thearray,value) {
// replacement for arrayname.push(value)
thearraysize = getarraysize(thearray);
thearray[thearraysize] = value;
return thearray[thearraysize];
}

function arraypop(thearray) {
// replacement for arrayname.pop()
thearraysize = getarraysize(thearray);
retval = thearray[thearraysize - 1];
delete thearray[thearraysize - 1];

thearray.length--; <<==我加了这句,很关键,否则出错
return retval;
}

// *******************************************************

另外给出网上几个老外写的

function Array_pop() {
var response = this[this.length - 1]
this.length--
return response
}

if (typeof(Array.prototype.pop) == "undefined") {
Array.prototype.pop = Array_pop
}

function Array_push() {
var A_p = 0
for (A_p = 0; A_p < arguments.length; A_p ) {
this[this.length] = arguments[A_p]
}
return this.length
}

if (typeof Array.prototype.push == "undefined") {
Array.prototype.push = Array_push
}

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:javascript做的数据校验(校验IP地址等)

下一篇:Ajax的宣传及现状:改变门户体验的技术