div+css实现一个可输入的下拉框
2014-11-21 19:56
375 查看
原文地址:http://xiguabaobao.com/46.html
不使用select元素,因为其无法输入且难以样式化,改用input元素组合一个列表元素ul来实现可输入的下拉框。
<!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=utf-8" />
<title>div+css实现一个可输入的下拉框</title>
<style type="text/css">
/*Reset*/
* {
margin:0;
padding:0;
}
ul {
list-style:none;
}
/*op*/
.op {
width:230px;
margin:10%;
border:1px solid #ccc;
}
.op-result {
width:200px;
padding:12px 15px;
border:none;
outline:none;
}
.op-list {
width:100%;
}
.hide {
display:none !important;
}
.op-list-item {
padding:12px 15px;
background-color:#f3f3f3;
cursor:pointer;
}
.op-list-item:hover {
background-color:#e3e3e3;
}
</style>
<script type="text/javascript">
function op_init(op){
if (!op) return;
var op_list = op.children[1];
if(op_list.className.indexOf('hide') > -1) {
op_list.className = op_list.className.replace(/(^|\s)hide(\s|$)/,'');
} else {
op_list.className += ' hide';
}
op_list.onclick = function(event){
if(event.target.className.indexOf('op-list-item') > -1){
op.children[0].value = event.target.innerHTML;
}
}
}
</script>
</head>
<body>
<div class="op" onclick="op_init(this);">
<input class="op-result" type="text" value="Click to select"/>
<ul class="op-list hide">
<li class="op-list-item">a</li>
<li class="op-list-item">b</li>
<li class="op-list-item">c</li>
</ul>
</div>
</body>
</html>
div+css实现一个可输入的下拉框
不使用select元素,因为其无法输入且难以样式化,改用input元素组合一个列表元素ul来实现可输入的下拉框。<!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=utf-8" />
<title>div+css实现一个可输入的下拉框</title>
<style type="text/css">
/*Reset*/
* {
margin:0;
padding:0;
}
ul {
list-style:none;
}
/*op*/
.op {
width:230px;
margin:10%;
border:1px solid #ccc;
}
.op-result {
width:200px;
padding:12px 15px;
border:none;
outline:none;
}
.op-list {
width:100%;
}
.hide {
display:none !important;
}
.op-list-item {
padding:12px 15px;
background-color:#f3f3f3;
cursor:pointer;
}
.op-list-item:hover {
background-color:#e3e3e3;
}
</style>
<script type="text/javascript">
function op_init(op){
if (!op) return;
var op_list = op.children[1];
if(op_list.className.indexOf('hide') > -1) {
op_list.className = op_list.className.replace(/(^|\s)hide(\s|$)/,'');
} else {
op_list.className += ' hide';
}
op_list.onclick = function(event){
if(event.target.className.indexOf('op-list-item') > -1){
op.children[0].value = event.target.innerHTML;
}
}
}
</script>
</head>
<body>
<div class="op" onclick="op_init(this);">
<input class="op-result" type="text" value="Click to select"/>
<ul class="op-list hide">
<li class="op-list-item">a</li>
<li class="op-list-item">b</li>
<li class="op-list-item">c</li>
</ul>
</div>
</body>
</html>
相关文章推荐
- 用DIV+CSS模拟textarea,实现文本框高度自适应用户输入的文本
- JS+CSS实现鼠标经过弹出一个DIV框完整实例(带缓冲动画渐变效果)
- 纯CSS实现圆角、可拖动的一个DIV模块层
- 一个CSS+DIV做的可拖动带遮罩层的DIV,圆角也是用CSS实现,欢迎大家拍砖
- CSS——DIV实现输入文字
- CSS_DIV学习记录2(用背景颜色实现一个网页的完整布局)
- css,js实现在鼠标移动到一个位置在这个位置下面显示一个已经存在的div,这个div的位置随意
- 如何在td里面的div里面放一个select下拉框实现
- CSS+jquery 实现滑动下拉框 DIV相对于浏览器固定位置
- 纯div+css实现手风琴效果下拉框的两种方法
- 一个非常实用的 div+css 实现的导航条
- JS+CSS实现鼠标经过弹出一个DIV框完整实例(带缓冲动画渐变效果)
- 可输入下拉框,css+js实现
- 纯CSS实现圆角、可拖动的一个DIV弹出层
- 给大家介绍一个日期输入控件javascript实现,我修改了下,符合我的习惯了,^_^!
- JS轻松实现CSS设置,DIV+CSS常用CSS设置
- div+css实现的滑动门,简洁,新手上路 (小鸽子系列)
- div+css实现的滑动门,简洁,新手上路 (小鸽子系列)
- javascript + DIV +CSS 实现可拖动消息窗体
- 一个类似MSN的提示风格的右下脚上浮的DIV-----JavaScript实现