here is a sample implementation, you can try to do AddNew,Delete:<Script Language=JavaScript>
function StringToRecordset(s)
{
  var a = s.split(/;/);
  this.recordCount = a.length;
  if (this.recordCount > 0)
  {
   this.recordset = new Array(a.length);   for (var i=0; i < a.length; i++)
   {
this.recordset[i] = a[i].split(/,/);
   }        this.MoveFirst();
  }
}function RecordsetToString()
{
  var s= "";
  if (this.recordset)
  {
   for (var i=0; i < this.recordset.length; i++)
s += ";"+this.recordset[i].join(","); if (s != "")
  s = s.substring(1);
  }  return s;
}function GetItem(n)
{
  if (!this.EOF())
    return this.recordset[this.cursor][n];
  else
    return null;
}function SetItem(n,v)
{
  if (!this.EOF())
    this.recordset[this.cursor][n] = v;
}
function MyRecordset()
{
  this.cursor = -1;
  this.recordCount = 0;
  this.recordset = null;
  this.RecordCount = function() {return this.recordCount;}
  this.StringToRecordset = StringToRecordset;
  this.RecordsetToString = RecordsetToString;
  this.MovePrevious = function() { if (this.recordCount > 0 && this.cursor >0) this.cursor--;};
  this.MoveNext = function () {if (this.recordCount > 0 && this.cursor < this.recordCount) this.cursor++; };
  this.MoveFirst = function() { if (this.recordCount >0) this.cursor = 0;};
  this.MoveLast  = function() { if (this.recordCount > 0) this.cursor = this.recordCount - 1;};
  this.BOF = function() {if (this.recordCount > 0) return this.cursor == -1; else return true;}
  this.EOF = function() { if (this.recordCount > 0) return this.cursor == this.recordCount; else return true;};
  this.GetItem = GetItem;
  this.SetItem = SetItem;
} var s="張三,男,湖南;李四,男,廣東;王娟,女,江西";
var myRs=new MyRecordset();
myRs.StringToRecordset(s);
while(!myRs.EOF())
{
var sValue=myRs.GetItem(0);
myRs.SetItem(0,sValue+"00");
myRs.MoveNext();
}
var sNew=myRs.RecordsetToString();
alert(sNew);
</Script>

解决方案 »

  1.   

    謝謝樓上的代碼
    對懂的人來說當然不難﹐但我做這份卷子前我還完全不知道怎樣自定義對象﹐怎樣定義方法屬性并調用。就象當你還不懂這個函數時execCommand你怎么知道怎樣怎樣做CSDN的文檔中心的那個編輯器呢?
      

  2.   

    sR="張三,男,湖南;李四,男,廣東;王娟,女,江西";function RS(name,data){
      this.name=name;
      this.data=data;
      this.record=data.split(';');
      this.count=this.record.length;  //this.EOF
      this.cursor=0;
      this.moveNext=moveNext;
      this.movePrevious=MovePrevious;
      this.moveLast=MoveLast;
      this.moveFirst=MoveFirst;
      this.addNew=AddNew;
      this.EOF=EOF;
      this.BOF=BOF;
      this.getItem=getItem;
      this.setItem=setItem;
    }function moveNext(){
       if(this.cursor<this.count)this.cursor++;
       return false;  
     }
     function movePrevious(){
       if(this.cursor!=0)this.cursor--;
       return false;
     }
     function BOF(){
       if(this.cursor==0)return true;
       return false;
     }
     function EOF(){
        if(this.cursor==this.count)return true;
        return false;
     }
     function moveLast(){
        this.cursor=this.count;
     }
     function moveFirst(){
        this.cursor=0;
     }
     function getItem(id){
       var fields=this.record[id].split(',');
       return fields;
     }
     function setItem(id){
         var arg=this.setItem.arguments;
         var fields=this.record[id].split(',');
         for(i=1;i<arg.length;i++){
         if(arg[i]!='')this.fields[i]=arg[i];//''就保留原值
     }
     var result='';
         for(i=0;i<fields.length;i++) {
        if(i!=fields.length-1)result+=fields[i]+',';
    else result+=fields[i];
    }
         this.record[id]=result;
     } function addNew(name,sex,address){
        var arg=this.addNew.arguments;
    var tmp='';
        if(!name||name=='') tmp+='noName'+this.record.length+',';
    if(!sex||sex=='') tmp+='male,';
    if(!address||address=='') tmp+='unknown';
    this.record[this.record.length]=tmp;
    }你说的那个字符串与对象呼转的函数就是RS的实例和RS.data的引用
    string to object:
    newRS=new RS(yourstr);
    object to string:
    yourstr=newRS.data;
      

  3.   

    修正错误!!!!!!!!!!!!
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML>
    <HEAD>
    <TITLE> New Document </TITLE>
    <META NAME="Generator" CONTENT="EditPlus">
    <META NAME="Author" CONTENT="">
    <META NAME="Keywords" CONTENT="">
    <META NAME="Description" CONTENT="">
    </HEAD><BODY>
    <SCRIPT LANGUAGE="JavaScript">
    <!--
    sR="張三,男,湖南;李四,男,廣東;王娟,女,江西";
    function RS(data){
      this.data=data;
      this.record=new Array;
      this.record=data.split(';');
      this.count=this.record.length;  this.cursor=0;
      this.moveNext=moveNext;
      this.movePrevious=movePrevious;
      this.moveLast=moveLast;
      this.moveFirst=moveFirst;
      this.addNew=addNew;
      this.EOF=EOF;
      this.BOF=BOF;
      this.getItem=getItem;
      this.setItem=setItem;
      this.deleteItem=deleteItem;
    }function moveNext(){
       if(this.cursor<this.count)this.cursor++;
       return false;  
     }
     function movePrevious(){
       if(this.cursor!=0)this.cursor--;
       return false;
     }
     function BOF(){
       if(this.cursor==0)return true;
       return false;
     }
     function EOF(){
        if(this.cursor==this.count)return true;
        return false;
     }
     function moveLast(){
        this.cursor=this.count;
     }
     function moveFirst(){
        this.cursor=0;
     }
     function getItem(id){
       var fields=this.record[id].split(',');
       return fields;//返回数组而不是字符串
     }
     function setItem(id){
         var arg=this.setItem.arguments;
         var fields=this.record[id].split(',');
         for(i=0;i<(arg.length-1);i++){
         if(arg[i+1]!='')fields[i]=arg[i+1];//''就保留原值
     }
     var result='';
         for(i=0;i<fields.length;i++) {
        if(i!=fields.length-1)result+=fields[i]+',';
    else result+=fields[i];
    }
         this.record[id]=result;
     } function addNew(name,sex,address){
        var arg=this.addNew.arguments;
    var tmp='';
        if(!name||name=='') tmp+='noName'+this.record.length+',';
    if(!sex||sex=='') tmp+='male,';
    if(!address||address=='') tmp+='unknown';
    this.record[this.record.length]=tmp;
    }
    function deleteItem(id){
       this.record.splice(id,1)
    }
    me=new RS(sR)
    alert(me.getItem(1))
    me.setItem(1,'llrock','male','beijing')
    alert(me.getItem(1))
    me.moveLast()
    alert('EOF='+me.EOF()+':'+'BOF='+me.BOF());
    me.moveFisrt();
    me.deleteItem(me.curcor);
    alert(me.getItem(me.cursor))
    //-->
    </SCRIPT>
    </BODY>
    </HTML>
      

  4.   

    这个不难的。你学习1天就可以掌握。作为初学javascript,我建议你可以看Windows Script 5.6带的文档中的JScript教程。虽然我认为那个没有Netscape的JavaScript 1.5 Guide写的好,不过是中文的。如果你不介意直接看英文资料,还是看Netscape的清楚一点。
      

  5.   

    謝謝各位的鼓勵﹐我現在看完答案已經明白﹐只是當時因為書中講得很簡單﹐找不到例子﹐無法理解﹐不爽歸不爽﹐地球一樣轉﹐好啦﹐收拾一下心情﹐繼續提高liuyxit(心随你动!)﹕當初一起來這里﹐一直比你稍領先一步﹐今天終于被你趕過了﹐恭喜你爬上第五座山﹐可以望星星了﹐不過我也只差几十分而已喔hax(海曦)﹕還記得我嗎﹐我在這里提的第一個問題就是你給了我非常詳細的解說﹐雖然無解﹐但也令我學到很多﹐你說那時你也是第一次得分﹐我們真有緣啊以后還請多指教回首一下﹐CSDN還真讓我學了不少