jQuery.Hashtable = function () { |
02 | this .items = new Array(); |
04 | this .add = function (key, value) { |
05 | if (! this .containsKey(key)) { |
06 | this .items[key] = value; |
10 | throw "key '" + key + "' allready exists." |
12 | this .get = function (key) { |
13 | if ( this .containsKey(key)) |
14 | return this .items[key]; |
19 | this .remove = function (key) { |
20 | if ( this .containsKey(key)) { |
21 | delete this .items[key]; |
25 | throw "key '" + key + "' does not exists." |
27 | this .containsKey = function (key) { |
28 | return typeof ( this .items[key]) != "undefined" ; |
30 | this .containsValue = function containsValue(value) { |
31 | for ( var item in this .items) { |
32 | if ( this .items[item] == value) |
37 | this .contains = function (keyOrValue) { |
38 | return this .containsKey(keyOrValue) || this .containsValue(keyOrValue); |
40 | this .clear = function () { |
41 | this .items = new Array(); |
44 | this .size = function () { |
45 | return this .itemsCount; |
47 | this .isEmpty = function () { |
48 | return this .size() == 0; |
=======================================================
var hashtable = new jQuery.Hashtable(); |
3 | $( '#btnAdd' ).click( function () { |
4 | hashtable.add($( '#txtAddKey' ).val(), $( '#txtAddValue' ).val()); |
6 | $( '#btnGet' ).click( function () { |
7 | alert(hashtable.get($( '#txtGetKey' ).val())) |
转载于:https://www.cnblogs.com/timy/archive/2010/08/01/1790020.html