options

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title> New Document </title>
<meta name="Generator" content="EditPlus">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
<script type="text/javascript">
function Map(linkItems) {
this.current = undefined;
this._size = 0;
if(linkItems === false){
this.disableLinking();
}
}
/**
* 获取当前map
* @return 当前对象
*/
Map.noop = function() {
return this;
};
/**
* 非法操作
* @return
*/
Map.illegal = function() {
throw new Error("非法操作,Map已经被禁用");
};
/**
*
* @param obj
* @param foreignKeys
* @return
*/
Map.from = function(obj, foreignKeys) {
var map = new Map;
for(var prop in obj) {
if(foreignKeys || obj.hasOwnProperty(prop)){
map.put(prop, obj[prop]);
}
}
return map;
};
/**
* 禁用map
* @return
*/
Map.prototype.disableLinking = function() {
this.link = Map.noop;
this.unlink = Map.noop;
this.disableLinking = Map.noop;
this.next = Map.illegal;
this.key = Map.illegal;
this.value = Map.illegal;
this.clear = Map.illegal;
return this;
};
/**
* 返回hash值 例如:number 123
* @param value key/value
* @return
*/
Map.prototype.hash = function(value) {
return (typeof value) + ' ' + (value instanceof Object ? (value.__hash || (value.__hash = ++arguments.callee.current)) : value.toString());
};
/**
* 返回map的长度
* @return
*/
Map.prototype.size = function() {
return this._size;
};

Map.prototype.hash.current = 0;
/**
* 通过key获取value
* @param key
* @return
*/
Map.prototype.get = function(key) {
var item = this[this.hash(key)];
return item === undefined ? undefined : item.value;
};
/**
* 向map中添加数据
* @param key 键
* @param value 值
* @return
*/
Map.prototype.put = function(key, value) {
var hash = this.hash(key);
if(this[hash] === undefined) {
var item = { key : key, value : value };
this[hash] = item;
this.link(item);
++this._size;
}else{
this[hash].value = value;
}
return this;
};
/**
* 通过key删除数据
* @param key
* @return
*/
Map.prototype.remove = function(key) {
var hash = this.hash(key);
var item = this[hash];
if(item !== undefined) {
--this._size;
this.unlink(item);
delete this[hash];
}
return this;
};
/**
* 清除map
* @return
*/
Map.prototype.clear = function() {
while(this._size){
this.remove(this.key());
}
return this;
};
/**
* 处理队列
* @param item
* @return
*/
Map.prototype.link = function(item) {
if(this._size == 0) {
item.prev = item;
item.next = item;
this.current = item;
}else {
item.prev = this.current.prev;
item.prev.next = item;
item.next = this.current;
this.current.prev = item;
}
};
Map.prototype.unlink = function(item) {
if(this._size == 0){
this.current = undefined;
}else {
item.prev.next = item.next;
item.next.prev = item.prev;
if(item === this.current){
this.current = item.next;
}
}
};
/**
* 获取下一个
* @return
*/
Map.prototype.next = function() {
this.current = this.current.next;
return this;
};
/**
* 获取key
* @return
*/
Map.prototype.key = function() {
return this.current.key;
};
/**
* 获取value
* @return
*/
Map.prototype.value = function() {
return this.current.value;
};
function a()
{
var map=new Map();
map.put('5',5);
map.put('1',1);



var ops = document.getElementById("sel").options;
for(i=0;i<ops.length;i++)
{
if(map.get(ops.options[i].value) != undefined)
{
//alert(map.get(ops.options[i].value));
ops.options.remove(i);
}
}

}

</script>
</head>

<body>



<select id="sel" style="width:200px">
<option value=1 alt="abc"> 1 </option>
<option value=2> 2 </option>
<option value=3> 3 </option>
<option value=4> 4 </option>
<option value=5> 5 </option>
<option value=6> 6 </option>
<option value=7> 7 </option>
<option value=8> 8 </option>
<option value=9> 9 </option>

</select>


<input type="button" value="aaaaaa" οnclick="a()">
</body>
</html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值