<script language="javascript" type="text/javascript">
function Hashtable()
{
this._hash = new Object();
this.add = function(key,value){
if(typeof(key)!="undefined"){
if(this.contains(key)==false){
this._hash[key]=typeof(value)=="undefined"?null:value;
return true;
} else {
return false;
}
} else {
return false;
}
}
this.remove = function(key){delete this._hash[key];}
this.count = function(){var i=0;for(var k in this._hash){i++;} return i;}
this.items = function(key){return this._hash[key];}
this.contains = function(key){ return typeof(this._hash[key])!="undefined";} //判断key是否存在
this.clear = function(){for(var k in this._hash){delete this._hash[k];}}
this.hasvalue = function(value){
for(var k in this._hash){
if(this._hash[k]==value){
return true;
}
}
return false;
}
this.getallvalues = function(){
var tmp="";
for(var k in this._hash){
tmp += k+","+a._hash[k]+";";
}
return tmp;
}
this.getjosnvalues = function(){
var tmp="{";
for(var k in this._hash){
tmp += k+":"+a._hash[k]+",";
}
tmp+="}";
return tmp;
}
this.getjosnitems = function(){
var tmp="[";
for(var k in this._hash){
tmp += "{"+k+":"+a._hash[k]+"},";
}
tmp=tmp.substring(0,tmp.length-1)+"]";
return tmp;
}
}
var a = new Hashtable();
a.add("aa");
a.add("bb",2342);
a.add("bb",2344);
alert(a.hasvalue(2342));
a.add("cc",2342);
for(var k in a._hash){
alert(k+":"+a._hash[k]);
}
alert("移除");
a.remove("aa");
for(var k in a._hash){
alert(k+":"+a._hash[k]);
}
alert("a.getallvalues():"+a.getallvalues());
alert("this.getjosnitems():"+this.getjosnitems());
/*
alert("计算总数");
alert(a.count());
alert("显示bb是否是数字");
alert(a.contains("bb"));
alert("显示aa是否是数字");
alert(a.contains("aa"));
alert("显示bb内容");
alert(a.items("bb"));
alert("显示aa内容");
alert(a.items("aa"));
*/
</script>