国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 編程 > JavaScript > 正文

JS表的模擬方法

2019-11-20 13:12:57
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

本文實(shí)例講述了JS表的模擬方法。分享給大家供大家參考。具體方法如下:

<!doctype html><html>  <head>    <meta charset="utf-8">    <title>列表</title>    <script>     function List(){      this.listSize= 0;      this.pos=0;      this.dataStore=[];//初始化一個(gè)空數(shù)組來(lái)保存列表元素      this.clear =clear;      this.find = find;      this.toString= toString;      this.insert = insert;      this.append= append;      this.remove =remove;      this.front = front;      this.end = end;      this.prev =prev;      this.next = next;      this.length= length;      this.currPos= currPos;      this.moveTo= moveTo;      this.getElement =getElement;      this.length = length;      this.contains = contains;      function append(element){        this.dataStore[this.listSize++] = element;      };      function find(element){        for(var i =0; i<this.dataStore.length; i++){          if(this.dataStore[i]===element){            return i ;          }        }        return -1;      }      function remove(element){        var foundAt =this.find(element);        if(foundAt!=-1){          this.dataStore.splice(foundAt,1);          this.listSize--;          return element;          //return true 原本是這樣,后面本人改為ELEMENT        }else{          return false;        }      }      function length(){        return this.listSize;      }      function toString(){        return this.dataStore;      }      function insert(element,after){        var insertPos = this.find(after);        if(insertPos!=-1){          this.dataStore.splice(insertPos+1,0,element);          this.listSize++;          return true;        }else{          return false;        }      }      function clear (){        delete this.dataStore;        this.listSize=0;        this.pos=0;        this.dataStore=[];      }      function contains(element){        for(var i =0; i<this.dataStore.length; i++){          if(this.dataStore[i]===element){            return true ;          }                }        return false;      }      function front(){        this.pos = 0;      }      function end(){        this.pos = this.listSize-1;      }      function prev(){        // if(this.pos> 0){          --this.pos;       // }      }      function next(){        // if(this.pos< this.listSize-1){          ++this.pos;        // }      }      function currPos(){        return this.pos;      }      function moveTo(pos){        this.pos= pos;           }      function getElement(){        return this.dataStore[this.pos];      }     }     var list = new List();     list.append({name:'夏廣成',sex:'男'});     list.append({name:'江榮盛',sex:'男'});     list.append({name:'杜強(qiáng)',sex:'男'});     list.append({name:'巧華',sex:'女'});     list.append({name:'方陽(yáng)',sex:'男'});    for(list.front(); list.currPos() < list.length() ; list.next()){     var item = list.getElement();     if(item.sex =='女'){      list.remove(item);     }    }    for(list.front(); list.currPos() < list.length() ; list.next()){     var item = list.getElement();      console.log(item.name);    }    </script>  </head>  <body >  </body></html>

希望本文所述對(duì)大家的javascript程序設(shè)計(jì)有所幫助。

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 铜川市| 台安县| 沅陵县| 堆龙德庆县| 阿勒泰市| 方城县| 遂宁市| 彭阳县| 旌德县| 广州市| 阿坝县| 临武县| 宣威市| 潮州市| 任丘市| 新绛县| 特克斯县| 滦南县| 镇远县| 永丰县| 中宁县| 和顺县| 维西| 大余县| 巴青县| 紫云| 潜山县| 威远县| 会同县| 奉新县| 景谷| 陆川县| 民乐县| 慈溪市| 宜兴市| 康保县| 郓城县| 香港 | 同仁县| 白银市| 睢宁县|