首頁| 新聞| 娛樂| 游戲| 科普| 文學| 編程| 系統| 數據庫| 建站| 學院| 產品| 網管| 維修| 辦公| 熱點
該類可以通過要害字(key)查找相對應的值(value),要害字的類型可以是String、Number、Boolean類型,值的類型不限,代碼如下:
運行代碼框<script>function struct(key, value){ this.key = key; this.value = value;}function setAt(key, value){ for (var i = 0; i < this.map.length; i ) { if ( this.map[i].key === key ) { this.map[i].value = value; return; } } this.map[this.map.length] = new struct(key, value);}function lookUp(key){ for (var i = 0; i < this.map.length; i ) { if ( this.map[i].key === key ) { return this.map[i].value; } } return null;}function removeKey(key){ var v; for (var i = 0; i < this.map.length; i ) { v = this.map.pop(); if ( v.key === key ) continue; this.map.unshift(v); }}function getCount(){ return this.map.length;}function isEmpty(){ return this.map.length <= 0;}function classMap() { this.map = new Array(); this.lookUp = lookUp; this.setAt = setAt; this.removeKey = removeKey; this.getCount = getCount; this.isEmpty = isEmpty;}window.onload = function(){ var map = new classMap(); alert("is the map empty? " map.isEmpty()); // string to array map.setAt("sw1", new Array("sw1_1")); map.setAt("sw2", new Array("sw2_1", "sw2_2")); map.setAt("sw3", new Array("sw3_1", "sw3_2", "sw3_3")); alert(map.lookUp("sw5")); // null alert(map.lookUp("sw2")); // "sw2_1, sw2_2" alert(map.getCount()); // 3 // number to string map.setAt(1, "sw1"); map.setAt(2, "sw2"); alert(map.lookUp(2)); // "sw2" map.setAt(2, new Array("sw2_1", "sw2_2")); alert(map.lookUp(2)); // "sw2_1, sw2_2" alert(map.getCount()); // 5 // string to number map.setAt("1", 1); map.setAt("2", 2); alert(map.lookUp("1")); // 1 alert(map.lookUp(1)); // "sw1" map.setAt("sw3", 33); alert(map.lookUp("sw3")); // 33 alert(map.getCount()); // 7 // number to number map.setAt(1, 11); map.setAt(2, 22); alert(map.lookUp(1)); // 11 alert(map.getCount()); // 7 map.removeKey(1); alert(map.lookUp(1)); // null alert(map.getCount()); // 6 // boolean to array map.setAt(false, new Array("false", "true")); alert(map.lookUp(false)); alert(map.getCount()); // 7}</script> [Ctrl A 全部選擇 提示:你可先修改部分代碼,再按運行]
練就火眼金睛 十一種常見電腦
打印機共享提示“操作無法完成
如何查找有故障的配件
回眸一笑百魅生,六宮粉黛無顏色
歲月靜美,剪一影煙雨江南
蕪湖有個“松鼠小鎮”
小滿:小得盈滿,一切剛剛好!
一串串晶瑩剔透的葡萄,像一顆顆寶石掛在藤
正宗老北京脆皮烤鴨
人逢知己千杯少,喝酒搞笑圖集
搞笑試卷,學生惡搞答題
新聞熱點
疑難解答
圖片精選
Dreamweaver問題集錦大全
Dreamweaver CS3 的最新功能
Dreamweaver CS3代碼片斷功能面板
Dreamweaver技巧:運用代碼片斷工具
網友關注