几个常用的Javascript函数

王朝java/jsp·作者佚名  2006-01-10
窄屏简体版  字體: |||超大  

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

// 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

}

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有  導航