JS:自定义带"count"参数的indexOf成员

代码如下: 

String.prototype.myIndexOf = function(childStr,startInd,count){
  
if (count == null){
   
return this.indexOf(childStr,startInd);
  }
else{
   
if (count < 0){return -1;};
   
for(i=count;i>1;i--){
    startInd 
= this.indexOf(childStr,startInd) + 1;
   }
 ;
   
return this.indexOf(childStr,startInd);
  }

 }

 

 

使用方法:

Code

 

注:第一个参数为要查找位置的子字符串,第二个参数为父字符串中开始查找的位置,第三个参数为要查询的出现次数。

 

 

posted @ 2008-11-19 15:14  hap  阅读(2772)  评论(0编辑  收藏  举报