首頁| 新聞| 娛樂| 游戲| 科普| 文學| 編程| 系統| 數據庫| 建站| 學院| 產品| 網管| 維修| 辦公| 熱點
該類可以通過要害字(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.{ 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技巧:運用代碼片斷工具
網友關注