javascript实现key value对象
JavaScript的实现的Map,用着挺方便的,不知道性能怎么样。
自己用只有不超过10个元素,所以性能无所谓了。
/********************jsmap.js**************************/
/////// map 类
function classMap() {
this.map = new Array();
var struct = function(key,
value){
this.key = key;
this.value = value;
};
this.lookUp = function (key){
for (var i = 0; i <
this.map.length; i++)
{
if ( this.map[i].key === key )
{
return this.map[i].value;
}
}
return null;
};
this.setAt = function (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);
};
this.removeKey = 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);
}
};
this.getCount = function(){
return
this.map.length;
};
this.isEmpty = function(){
return this.map.length <= 0;
};
}
////////////////////////////////////////////////////////////////////////////////////////////////
/********************调用***********************/
window.onload = function(){
var map = new classMap();
alert("is the map empty? " +
map.isEmpty());
// string to array
map.setAt("sw1", "aaaa
相关文档:
研究了半天,不过貌似还是只能在IE上实现,其他浏览器不支持EMBED 标签
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>用javascript制作超链接的背景音效</title>
<script language="JavaScript" type="text/JavaScript">
<!--
......
代码主要是操作cookie的两个函数:一个是setCookie用于设置cookie的值,另外一个是getCookie 用于取cookie的值,实现了简单的cookie存取操作,很简单,代码如下:
<mce:script language="JavaScript" type="text/javascript"><!--
function setCookie(name,value)
{
//用于存储赋值给document.cookie的c ......
<!--
/* Font Definitions */
@font-face
{font-family:宋体;
panose-1:2 1 6 0 3 1 1 1 1 1;
mso-font-alt:SimSun;
mso-font-charset:134;
mso-generic-font-family:auto;
mso-font-pitch:variable;
mso-font-signature:3 135135232 16 0 262145 0;}
@font-face
{font-family:"\@宋体" ......
// 保存Cookie
function saveCookie(name, value, expires, path, domain, secure){
var strCookie = name +& ......