87,992
社区成员
发帖
与我相关
我的任务
分享<div id="divtest" style="width:980px;background-color:green;position:absolute;z-index:1;">
<ul id="list">
<li>张柏芝</li>
<li>林心如</li>
<li>李小璐</li>
<li>王骆丹</li>
</ul>
</div>
<input type="text" id="txtInput" onfocus="txtFocus()" onkeyup="txtChange()" />
<script type="text/javascript">
function txtFocus() {
var txtInput = document.getElementById("txtInput");
var divList = document.getElementById("list");
if (txtInput.value != "") {
divList.style.display = "block";
}
}
function txtChange() {
var txtInput = document.getElementById("txtInput");
var divList = document.getElementById("list");
if (txtInput.value != "") {
itembind();
divList.style.display = "block";
}
else {
divList.style.display = "none";
}
}
function itembind(){
var item=document.getElementById("list").getElementsByTagName("li");
for(i=0;i<item.length;i++)
{
item[i].onclick=function(){
document.getElementById("txtInput").value=this.innerHTML;
document.getElementById("list").style.display='none';
}
}
}
</script>