Dieser Artikel beschreibt die Simulationsmethode der JS -Tabelle. Teilen Sie es für Ihre Referenz. Die spezifischen Methoden sind wie folgt:
<! docType html> <html> <kopf> <meta charset = "utf-8"> <title> list </title> <script> Funktionsliste () {this.listize = 0; this.pos = 0; this.datastore = []; // initialisieren Sie ein leeres Array, um das Listenelement zu speichern. Clear = Clear; this.find = find; this.toString = toString; this.insert = Insert; this.Append = append; this.remove = entfernen; this.front = vorne; this.end = Ende; this.prev = prev; this.Next = Weiter; diese.länge = Länge; this.currpos = currpos; this.moveto = moveto; this.getElement = GetElement; diese.länge = Länge; this.contains = enthält; Funktion append (Element) {this.datastore [this.listSize ++] = Element; }; Funktion find (element) {for (var i = 0; i <that thatastore.length; i ++) {if (this.datastore [i] === Element) {return i; }} return -1; } Funktion entfernen (Element) {var foundat = this.find (Element); if (fotzat! this.listize--; Rückgabeelement; // RETURE WAHR ERHALT Es war ursprünglich so, ich habe es in Element} else {return false; }} Funktion Länge () {return this.listSize; } function toString () {return this.datastore; } Funktion Insert (Element nach) {var Insertpos = this.find (nach); if (InsertPos! this.listize ++; zurückkehren; } else {return false; }} Funktion clear () {löschen this.datastore; this.listSize = 0; this.pos = 0; this.datastore = []; } Funktion enthält (Element) {for (var i = 0; i <thataTastore.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; //}} Funktion next () {// if (this.pos <this.listize-1) {++ this.pos; //}} Funktion Currpos () {return this.pos; } function moveTo (pos) {this.pos = pos; } function getElement () {return this.datastore [this.pos]; }} var list = new list (); list.append ({name: 'xia guangcheng', sex: 'männlich'}); list.append ({name: 'jiang rongsheng', sex: 'male'}); list.append ({name: 'du Qiang', Sex: 'männlich'}); list.append ({name: 'qiaohua', Sex: 'weiblich'}); list.append ({name: 'fang yang', sex: 'männlich'}); list.append ({name: 'fang yang', sex: 'männlich'}); für (list.front (); list.currpos () <list.length (); list.Next ()) {var item = list.getElement (); if (item.sex == 'weiblich') {list.remove (item); }} für (list.front (); list.currpos () <list.length (); list.Next ()) {var item = list.getElement (); console.log (item.name); } </script> </head> <body> </body> </html>Ich hoffe, dieser Artikel wird für JavaScript -Programme aller hilfreich sein.