textbox点击加载li数据

本文介绍了一种使用HTML、CSS和JavaScript实现自定义下拉框的方法。该方法通过鼠标点击事件展示和隐藏下拉选项,并实现了选项选择后的文本显示功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>
textbox点击加载li数据

</title>

<style type="text/css">

 #div ul{
  list-style:none;
  padding:0;
  margin:0;
  border:1px solid #000000;
  width:100%;
  position: absolute;
  left: 0px;
  top: 0px;
  background-color:#FFFFFF;
  z-index:200;
 }
 #div ul li{
  width:300px;
  padding:0;
  background:#fff;

 }
 .select_box {
     position: relative; 
     z-index:10;
 }
 .select_box select {
     position:fixed; 
     z-index:100;
 }
</style>
</head>
<body>
   
<select name="ctl00$mainContent$ddlRptName" id="ctl00_mainContent_ddlRptName" class="ddListNormal" style="width:148px;display:none;">
 <option selected="selected" value=""></option>
 <option value="01">aaaaaaaaaaaaa</option>
 <option value="02">bbbbbbbbbbbbb</option>
 <option value="04">ccccccccccccc</option>
 <option value="05">ddddddddddddd</option>
 <option value="06">eeeeeeeeeeeee</option>
 <option value="07">fffffffffffff</option>
</select>
<div id="div" style=" width:100px; position:relative; z-index :20">
 <input name="ctl00$mainContent$ddlRpt" type="text" id="ctl00_mainContent_ddlRpt" onClick="focusHandler(this)" onBlur="hideul()" />
 
 <ul style='display:none;'>
 
  <li title= onClick= clickHandler(this) onMouseOver= mouseoverHandler(this) onMouseOut= mouseoutHandler(this)> <span style='font-size:12px;'></span></li>
  
  <li title=aaaaaaaaaaaaa onClick= clickHandler(this) onMouseOver= mouseoverHandler(this) onMouseOut= mouseoutHandler(this)> <span style='font-size:12px;'>aaaaaaaaaaaaa</span></li>
  
  <li title=bbbbbbbbbbbbb onClick= clickHandler(this) onMouseOver= mouseoverHandler(this) onMouseOut= mouseoutHandler(this)> <span style='font-size:12px;'>bbbbbbbbbbbbb</span></li>
  
  <li title=ccccccccccccc onClick= clickHandler(this) onMouseOver= mouseoverHandler(this) onMouseOut= mouseoutHandler(this)> <span style='font-size:12px;'>ccccccccccccc</span></li>
  
  <li title=ddddddddddddd onClick= clickHandler(this) onMouseOver= mouseoverHandler(this) onMouseOut= mouseoutHandler(this)> <span style='font-size:12px;'>ddddddddddddd</span></li>
  
  <li title=eeeeeeeeeeeee onClick= clickHandler(this) onMouseOver= mouseoverHandler(this) onMouseOut= mouseoutHandler(this)> <span style='font-size:12px;'>eeeeeeeeeeeee</span></li>
  
  <li title=fffffffffffff onClick= clickHandler(this) onMouseOver= mouseoverHandler(this) onMouseOut= mouseoutHandler(this)> <span style='font-size:12px;'>fffffffffffff</span></li>
 </ul>
</div>
              

<SCRIPT LANGUAGE="JavaScript">

var flag = false;
document.getElementById("div").getElementsByTagName('ul')[0].style.display = 'none';
function focusHandler(obj) {
 if (obj.parentNode)
  obj.parentNode.getElementsByTagName('ul')[0].style.display = '';
}
function clickHandler(obj) {
 obj.parentNode.parentNode.getElementsByTagName("input")[0].value = obj.title;
 obj.parentNode.style.display = "none";
}
function mouseoverHandler(obj) {
 flag = true;
 obj.style.cursor = 'default';
 obj.style.backgroundColor = "#0066CC";
}
function mouseoutHandler(obj) {
 flag = false;
 obj.style.backgroundColor = "";
 obj.style.border = "";
}
function hideul() {
 if (flag == false) {
  document.getElementById("div").getElementsByTagName('ul')[0].style.display = 'none';
 } else {
  return false;
 }

}

</SCRIPT>

</body>

</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值