이 기사에서는 JS 테이블의 시뮬레이션 방법에 대해 설명합니다. 참조를 위해 공유하십시오. 특정 방법은 다음과 같습니다.
<! doctype html> <html> <head> <meta charset = "utf-8"> <title> 목록 </title> <cript> 함수 list () {this.listsize = 0; this.pos = 0; this.datastore = []; // 목록 요소를 저장하기 위해 빈 배열을 초기화하십시오. this.clear = clear; this.find = 찾기; this.tostring = Tostring; this.insert = 삽입; this.append = Append; this.remove = 제거; this.front = Front; this.end = 끝; this.prev = 이전; this.next = 다음; 길이 = 길이; this.currpos = Currpos; this.moveto = moveto; this.getElement = getElement; 길이 = 길이; this.contains = contains; 함수 append (요소) {this.datastore [this.listsize ++] = 요소; }; 함수 찾기 (element) {for (var i = 0; i <this.datastore.length; i ++) {if (this.datastore [i] === 요소) {return i; }} 반환 -1; } 함수 제거 (요소) {var foundat = this.find (element); if (foundat! = -1) {this.datastore.splice (foundat, 1); this.lissize-; 리턴 요소; // return true는 원래 이것과 같았습니다. 요소로 변경했습니다} else {return false; }} function length () {return this.listsize; } function toString () {return this.datastore; } 함수 삽입 (요소, 후) {var insertpos = this.find (후); if (insertpos! = -1) {this.datastore.splice (insertpos+1,0, 요소); this.listsize ++; 진실을 반환하십시오. } else {return false; }} function clear () {this.datastore; this.listsize = 0; this.pos = 0; this.datastore = []; } 함수는 (요소) {for (var i = 0; i <this.datastore.length; i ++) {if (this.datastore [i] === 요소) {return true; }} 거짓을 반환합니다. } 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; } 함수 moveto (pos) {this.pos = pos; } function getElement () {return this.datastore [this.pos]; }} var list = new List (); list.append ({이름 : 'Xia Guangcheng', 섹스 : 'male'}); list.append ({이름 : 'Jiang Rongsheng', 섹스 : 'male'}); list.append ({이름 : 'du qiang', 섹스 : 'male'}); list.append ({이름 : 'Qiaohua', 섹스 : '여성'}); list.append ({이름 : 'Fang Yang', 섹스 : 'male'}); list.append ({이름 : 'Fang Yang', 섹스 : 'male'}); for (list.front (); list.currpos () <list.length (); list.next ()) {var item = list.getElement (); if (item.sex == 'female') {list.remove (항목); }} for (list.front (); list.currpos () <list.length (); list.next ()) {var item = list.getElement (); Console.log (item.name); } </script> </head> <body> </body> </html>이 기사가 모든 사람의 JavaScript 프로그래밍에 도움이되기를 바랍니다.