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
相关文档:
父窗口中有三种方式打开子窗口:
1:
window.open(URL,windowName,parameters);
2:
alert(""); //弹出信息提示对话框
confirm(""); //弹出信息确认对话框
prompt(""); //具有交互性质的对话框
3:
//创建模态你对话框
window.showModalDialog(sURL,vArguments,sFeatures)
//创建非模态对话框
window.showM ......
现在网页上的字体是越来越小,别说是视力欠佳者就是好眼睛看久了也疼的难受,于是编写了下面这段小脚本,建议网页制作人能够加到网页代码的< head>中,以方便弱视人群放大浏览(仅适用于IE浏览器)!
代码如下:
< script language="javascript">
var i=0;
document.onkeydown = zoom;
......
这部分说一下最近非常流行的事件代理。事件代理的实现简单来说,是把事件绑定到目标元素的祖先元素上,然后通过冒泡或捕获得到事件源,然后再判定事件源是否等于目标元素再执行回调函数。由于对目标元素的判定有时非常模糊,因此通过判定即可调用回调函数,这样,我们就达到一个监听器为许多事件源服务的目的。对于性能一向 ......
<%@ Page Language="C#" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server"> </script>
<html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server">
<title ......