zoukankan      html  css  js  c++  java
  • jquery hashtable

    jQuery.Hashtable = function() {
    02     this.items = new Array();
    03     this.itemsCount = 0;
    04     this.add = function(key, value) {
    05         if (!this.containsKey(key)) {
    06             this.items[key] = value;
    07             this.itemsCount++;
    08         }
    09         else
    10             throw "key '" + key + "' allready exists."
    11     }
    12     this.get = function(key) {
    13         if (this.containsKey(key))
    14             return this.items[key];
    15         else
    16             return null;
    17     }
    18   
    19     this.remove = function(key) {
    20         if (this.containsKey(key)) {
    21             delete this.items[key];
    22             this.itemsCount--;
    23         }
    24         else
    25             throw "key '" + key + "' does not exists."
    26     }
    27     this.containsKey = function(key) {
    28         return typeof (this.items[key]) != "undefined";
    29     }
    30     this.containsValue = function containsValue(value) {
    31         for (var item in this.items) {
    32             if (this.items[item] == value)
    33                 return true;
    34         }
    35         return false;
    36     }
    37     this.contains = function(keyOrValue) {
    38         return this.containsKey(keyOrValue) || this.containsValue(keyOrValue);
    39     }
    40     this.clear = function() {
    41         this.items = new Array();
    42         itemsCount = 0;
    43     }
    44     this.size = function() {
    45         return this.itemsCount;
    46     }
    47     this.isEmpty = function() {
    48         return this.size() == 0;
    49     }
    50 };
     

    =======================================================

    var hashtable = new jQuery.Hashtable();
    2 $(function() {
    3     $('#btnAdd').click(function() {
    4         hashtable.add($('#txtAddKey').val(), $('#txtAddValue').val());
    5     });
    6     $('#btnGet').click(function() {
    7         alert(hashtable.get($('#txtGetKey').val()))
    8     });
    9 })
  • 相关阅读:
    setup命令开机启动服务配置
    setup命令网卡配置
    ARM架构与ARM内核
    菁华开示目录
    末法时代选修净土法门可得解脱
    净宗之声 | 向知识分子介绍净土法门(文声对照)
    1217. 无量寿经颂序
    150.2 重刻安士全书序二
    往生典范|黄忠昌往生记实+西方发愿文+止语的好处等
    深度揭秘|邪淫、艳遇背后的真相(影音+图文)
  • 原文地址:https://www.cnblogs.com/timy/p/1790020.html
Copyright © 2011-2022 走看看