首頁 > web前端 > js教程 > js採用map取到id集合組並且實作點選一行選中一行_javascript技巧

js採用map取到id集合組並且實作點選一行選中一行_javascript技巧

WBOY
發布: 2016-05-16 17:08:43
原創
1138 人瀏覽過
複製程式碼 程式碼如下:



🎜>
1
樓盤開業
折扣大大
2011-11-11
簡訊通知


2
樓盤開業
折扣大大
2011-11- 11
簡訊通知




div>

}); }); }); >});
复制代码 代码如下:

function HashMap()
{
/**Map size **/
var size = 0;
/**Object **/
var entry = new Object();

/**live **/
this.put = function (key , value)
{
if(!this.containsKey(key))
{
size ;
}
entry[key] = value;
}

/**Pick **/
this.get = function (key)
{
if( this.containsKey(key) )
{
return entry[key];
}
else
{
return null;
}
}

/**delete **/
this.remove = function ( key )
{
if( delete entry[key] )
{
size --;
}
}

/**Whether to include Key **/
this.containsKey = function ( key )
{
return (key in entry);
}

/**Whether to include Value **/
this.containsValue = function ( value )
{
for(var prop in entry)
{
if(entry[prop] == value)
{
return true;
}
}
return false;
}

/**All Value **/
this.values = function ()
{
var values = new Array(size);
for(var prop in entry)
{
values.push(entry[prop]);
}
return values;
}

/**All Key **/
this.keys = function ()
{
var keys = new Array(size);
for(var prop in entry)
{
keys.push(prop);
}
return keys;
}

/**Map Size **/
this.size = function ()
{
return size;
}
}

// var map = new HashMap();

/*
map.put("A","1");
map.put("B","2");
map.put("A","5");
map.put("C","3");
map.put("A","4");
*/

/*
alert(map.containsKey("XX"));
alert(map.size());
alert(map.get("A"));
alert(map.get("XX"));
map.remove("A");
alert(map.size());
alert(map.get("A"));
*/

/**You can also use the object as Key **/
/*
var arrayKey = new Array("1","2","3","4");
var arrayValue = new Array("A","B","C","D");
map.put(arrayKey,arrayValue);
var value = map.get(arrayKey);
for(var i = 0 ; i < value.length ; i )
{
//alert(value[i]);
}
*/
/**When an object is used as a Key, the toString() method of the object is automatically called. In fact, the String object is ultimately used as the Key**/

/**If it is a custom object, you have to override the toString() method. Otherwise, . will be the following result **/

// function MyObject(name)
// {
// this.name = name;
// }

/**
function MyObject(name)
{
this.name = name;

this.toString = function ()
{
return this.name;
}
}
**/
// var object1 = new MyObject("小张");
// var object2 = new MyObject("小名");
//
// map.put(object1,"小张");
// map.put(object2,"小名");
// alert(map.get(object1));
// alert(map.get(object2));
// alert(map.size());
//
/**Running result Nickname Nickname size = 1 **/

/**If you change it to an object that overrides the toString() method, the effect will be completely different **/
相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板