<!DOCTYPE html>
<html>
<meta charset="utf-8">
<head>
<title></title>
<style type="text/css">
body,
div,input,ul{
margin: 0;
padding: 0;
font-family: "\96B6\4E66",Helvetica,sans-serif;
font-size:20px;
outline: none;
}
a,a:hover,a:active,a:target{
display:block;
text-decoration: none;
color:#000;
}
ul{
list-style: none;
}
html,body{
width:100%;
height:100%;
border-top: 1px solid transparent;
}
.box{
margin:20px auto;
width: 500px;
}
.box #input{
display:block;
width:300px;
height: 30px;
padding:0 10px;
border-bottom-color: white;
position:relative;
z-index: 2;
}
.box ul{
display: none;
position:relative;
top:-1px;
border:1px solid #EEEEE0;
}
.box ul li,.box ul li a{
height: 35px;
line-height: 35px;
}
.box ul li a{
padding: 0 10px;
}
.box ul li a:hover{
background-color:#EEEEE0;
}
</style>
</head>
<body>
<div class="box">
<input type="text" id="input">
<ul id="ullist">
<li><a href="javascript:;">你好1</a></li>
<li><a href="javascript:;">你好2</a></li>
<li><a href="javascript:;">你好3</a></li>
<li><a href="javascript:;">你好4</a></li>
</ul>
</div>
<script type="text/javascript">
var input=document.getElementById("input");
var ullist=document.getElementById("ullist");
input.onfocus=input.onkeyup=function(){
var value=this.value.replace(/^ +| +$/g,"")
ullist.style.display=value.length>0?"block":"none";
}
document.body.onclick=function(e){
e=e||window.event;
e.target=e.target||e.srcElement;
if(e.target.tagName.toLowerCase()==="a"&&e.target.parentNode.tagName==="LI"){
ullist.style.display="none";
input.value=e.target.innerHTML;
return;
}
input.onclick=function(e){
e=e||window.event;
e.stopPropagation?e.stopPropagation():e.cancelBubble=true;
}
ullist.style.display="none";
}
</script>
</body>
</html>