javascript 校验某个数组中的所有元素是否相同...
时间:2010-08-17 来源:guixiang155cm
/** compare elements **/ function _compare_element(a){ var temp = a[0]; this.flag = false; this._verify_ele = function(){ for(var c = 0 ; c < a.length; c ++){ if( temp == a[parseInt(c)]) { this.flag = true; continue; } else{ this.flag = false; break; } } return this.flag; }; return this._verify_ele; } /** test fn **/ function aa(){ var a1=[2,2,2,2,2,2]; var fn = new _compare_element(a1); if(fn()){ document.write("elements of array are the same..."); return; } document.write("elements of array are not the same..."); }
output : elements of array are the same...
相关阅读 更多 +