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.onclick=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]){
onclick=function(){
me.spanObj.innerHTML=me.inputObj.value=this.innerHTML;
me.ulObj.style.display="none";
}
onmouseover=function(){
this.className=me.hoverClass;
}
onmouseout=function(){
this.className="";
}
}
}
},
spanInit:function(){
var me=this;
this.spanObj.onclick=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>

你可能感兴趣的:(html)