2008 2008年 9月 1日
从JavaScript数组传递的字符串相匹配的特定项目
这里的快速扩大本地的JavaScript数组对象,只是为了做到这一点的方式...
Array.prototype. removeItem =function(str) {
for(i=0; i<this.length ; i++){
if(escape(this[i]).match(escape(str.trim()))){
this.splice(i, 1); break;
}
}
return this;
}
所以,现在你可以做这样的事情......
var animals= new Array("dog","lion","cat","tiger","elephant");
animals. removeItem ('tiger');现在的动物数组将包含“狗”,“狮子”,“猫”,“大象”;
注:这里是字符串修剪原型...
String.prototype.trim=function(str) {
str = this != window? this : str;
return str.replace(/^\s+/g, '').replace(/\s+$/g, '');
}
享受....










































