checkbox模拟 select模拟

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style>
* { margin:0px; padding:0px; }
#checkboxmn{ display:block; height:100px; width:100px; cursor:pointer; background:#ccc;}
#checkboxmn.libag{ background:blue;}
#checkboxmn2{ display:block; height:100px; width:100px; cursor:pointer; background:#ccc;}
#checkboxmn2.libag{ background:blue;}
</style>
</head>
<script>
function mnCheckbox(obj){
var myself=this;
this.mnId= document.getElementById(obj.mnId);
this.checkboxId=document.getElementById(obj.checkboxId);
this.hotClass=obj.hotClass||"";
this.init();
}
mnCheckbox.prototype={
init:function(){
this.mnInit();
},
mnInit:function(){
var me=this;
this.mnId.οnclick=function(){
if(this.className.replace(" ","")==me.hotClass){
this.className="";
me.checkboxId.checked=false;
}
else{
this.className=me.hotClass;
me.checkboxId.checked=true;
}
}
}
}
</script>
<body>
<span class=" " id="checkboxmn"></span>
<input type="checkbox" id="checkboxmnt"/>
</body>
<script>
var user=new mnCheckbox({mnId:"checkboxmn",checkboxId:"checkboxmnt",hotClass:"libag"});
</script>
</html>

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style>
* { margin:0px; padding:0px; }
.mnsel { position:relative; width:150px; float:left; }
.mnsel span { display:block; width:150px; height:20px; background:#cccccc; cursor:pointer; }
.mnsel ul li { height:20px; line-height:20px; border:1px solid #999999; border-top:0px; cursor:pointer; }
.libag { background:#939; }
</style>
</head>
<script>
function mnSelect(obj){
var myself=this;
this.spanObj= document.getElementById(obj.spanId);
this.ulObj=document.getElementById(obj.ulId);
this.inputObj=document.getElementById(obj.inputId);
this.speed=obj.speed||0;
this.hoverClass=obj.hoverClass||"";
this.init();
}
mnSelect.prototype={
init:function(){
if(this.ulObj.childNodes.length>0){
this.liInit();
this.spanInit();
this.ulObj.childNodes[0].onclick();}
},
liInit:function(){
var me=this;
for(var a=0;a<this.ulObj.childNodes.length;a++)
{
with(this.ulObj.childNodes[a]){
οnclick=function(){
me.spanObj.innerHTML=me.inputObj.value=this.innerHTML;
me.ulObj.style.display="none";
}
οnmοuseοver=function(){
this.className=me.hoverClass;
}
οnmοuseοut=function(){
this.className="";
}
}
}
},
spanInit:function(){
var me=this;
this.spanObj.οnclick=function(){
if(me.ulObj.style.display=="none"){me.ulObj.style.display="block"}
else{me.ulObj.style.display="none";}
}
}
}

</script>
<body>
<div class="mnsel"> <span id="mnsel2"></span>
<ul id="ulid2" style="display:none;">
<li class="xxx">23enllish</li>
</ul>
</div>
<form>
<input type="hidden" id="ycsel2" value="wo"/>
</form>
</body>
<script>
var user=new mnSelect({spanId:"mnsel2",ulId:"ulid2",inputId:"ycsel2",speed:300,hoverClass:"libag"});
</script>
</html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值