input 下拉框 的实践
有一个需求 需要做一个input 框 点击出现列表
于是想到了 datalist控件
<input type="text" list="itemlist" name="" class="search" >
<datalist id="itemlist">
<option>常用001</option>
<option>item2</option>
<option>item3</option>
<option>item4</option>
<option>item5</option>
<option>item6</option>
</datalist>
于是乎看了 张大神的文章
http://www.zhangxinxu.com/wordpress/2013/03/html5-datalist-%E5%AE%9E%E9%99%85%E5%BA%94%E7%94%A8-%E5%8F%AF%E8%A1%8C%E6%80%A7/
学习了 怎么匹配到邮箱 但是 默认的灰色 边框去不掉 还是有很大局限性
于是只能看自己的了
代码 部分 :实现传值 的问题
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
<title>搜索框</title>
<style>
.input-box {
position: relative;
display: inline-block;
}
.input-box .input {
background-color: transparent;
background-image: none;
border: 1px solid #ccc;
border-radius: 4px;
box-shadow: 0 1px 1px rgba(0, 0, 0, 0.075) inset;
color: #555;
display: block;
font-size: 14px;
line-height: 1.42857;
padding: 6px 6px;
transition: border-color 0.15s ease-in-out 0s, box-shadow 0.15s ease-in-out 0s;
width: 200px;
display: inline;
position: relative;
z-index: 1;
}
.tip-l {
width: 0;
height: 0;
border-left: 5px solid transparent;
border-right: 5px solid transparent;
border-top: 10px solid #555;
display: inline-block;
right: 10px;
z-index: 0;
position: absolute;
top: 12px;
}
.dropdown {
position: absolute;
top: 32px;
left: 0px;
width: 212px;
background-color: #FFF;
border: 1px solid #23a8ce;
border-top: 0;
box-shadow: 0 1px 1px rgba(0, 0, 0, 0.075) inset;
z-index: 999;
padding: 0;
margin: 0;
}
.dropdown li {
display: block;
line-height: 1.42857;
padding: 0 6px;
min-height: 1.2em;
cursor: pointer;
}
.dropdown li:hover {
background-color: #23a8ce;
color: #FFF;
}
</style>
<!-- // <script src="../js/jquery-2.1.0.js"></script> -->
<script src="http://libs.baidu.com/jquery/2.1.4/jquery.min.js"></script>
</head>
<body>
<div class="input-box">
<input type="text" class="input" value="Holle Word" />
<span class="tip-l"></span>
<ul class="dropdown">
<li >Holle Word</li>
<li >这是一个测试</li>
<li >简单的dome</li>
</ul>
</div>
</body>
<script>
var isBox = false; // 定义一个触发焦点事件的开关,默认为不开启状态 || 也可以给input设置一个属性,来判断
$(".dropdown").hide();
$(".input").focus(function () { // input绑定焦点事件,触发时打开焦点开关
$(this).siblings(".dropdown").show();
isBox = true;
});
$(".input-box").mousemove(function () { // 鼠标进入input-box区域内打开焦点开关
isBox = true;
});
$(".input-box").mouseout(function () { // 鼠标离开input-box区域内关闭焦点开关
isBox = false;
});
$(".input").blur(function () { // input失去焦点时通过焦点开关状态判断鼠标所在区域
if (isBox == true) return false;
$(this).siblings(".dropdown").hide();
});
$(".dropdown").find('li').each(function () { // 传值给input,同时关闭焦点开关
$(this).on("click", function () {
isBox = false;
var text = $(this).text();
$(this).parent().siblings(".input").val(text);
$(".dropdown").hide();
})
})
</script>
</html>
input 下拉框 的实践的更多相关文章
- Bootstrap modal模态框关闭时,combobox input下拉框仍然保留在页面上
问题描述: 当点击模态框的关闭按钮时,下拉框中的内容没有消失,而是移动到了页面左上角 分析:这个问题的定位在于是用的哪种模态框,bootstrap和easyui都可以实现模态框,但是两个方法实现的模态 ...
- jquery input 下拉框(模拟select控件)焦点事件
本章主要讲解如何实现select下拉列表可输入效果 ps:input提供输入,然后用ul去模拟一个select下拉列表效果即可,关键在于点击div之外的地方隐藏ul,下面是html基本结构: < ...
- input下拉框
用Html5和css.js写的,引用的bootstrap和jquery文件请各位看客自己去下载
- jquery div 下拉框焦点事件
这章与上一张<jquery input 下拉框(模拟select控件)焦点事件>类似 这章讲述div的焦点事件如何使用 div的焦点事件与input的焦点事件区别在于 需要多添加一个属性: ...
- 用div,ul,input模拟select下拉框
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title&g ...
- struts2 jsp表单提交后保留表单中输入框中的值 下拉框select与input
原文地址:struts2 jsp表单提交后保留表单中输入框中的值 下拉框select与input jsp页面 1 function dosearch() {2 if ($(&q ...
- 使用jquery-combobox实现select下拉框多选之后,如何将下拉框的值传给input隐藏域
我在之前的一篇博文中eaeyui-combobox实现组合查询(即实现多个值得搜索)地址:http://www.cnblogs.com/dushan/p/4778897.html 实现了select下 ...
- 【jQuery获取下拉框select、单选框radio、input普通框的值和checkbox选中的个数】
radio单选框:name属性相同 <input type="radio" id="sp_type" name="p_type" va ...
- jquery.editable-select 可编辑下拉框之获取select值和input值
使用jquery.editable-select可以实现可编辑下拉框的功能,但需要先导入jquery.js,jquery.editable-select.css,jquery.editable-sel ...
随机推荐
- doctotext
文档解析库 http://www.it610.com/article/1936051.htm
- [SoapUI] Command-Line Arguments
https://support.smartbear.com/readyapi/docs/soapui/running/automating/cli.html Use the test runner t ...
- 2018.07.28 uoj#164. 【清华集训2015】V(线段树)
传送门 线段树好题. 要求支持的操作: 1.区间变成max(xi−a,0)" role="presentation" style="position: rela ...
- hdu-1253(bfs+剪枝)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1253 思路:简单的bfs,就是要注意剪枝. #include<iostream> #inc ...
- hdu-1026(bfs+优先队列)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1026 题意:输入n,m和一个n*m的矩阵, .表示通路: x表示墙: n表示有一个怪物,消灭它需要n个 ...
- asp.net Hessian 服务的注册
Hessian服务端实现了IHttpHandle, 默认情况下是在Web.Config中的handles接点中注册,这样当有 很多实现时比较麻烦 这个时候可以实现IHttpHandleFactory注 ...
- UVaLive 2796 Concert Hall Scheduling (最小费用流)
题意:个著名的音乐厅因为财务状况恶化快要破产,你临危受命,试图通过管理的手段来拯救它,方法之一就是优化演出安排,既聪明的决定接受或拒绝哪些乐团的演出申请,使得音乐厅的收益最大化.该音乐厅有两个完全相同 ...
- 配置 cxf-ws spring bean 文件
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...
- (线段树 区间查询更新) Can you answer these queries? -- hdu--4027
链接: http://acm.hdu.edu.cn/showproblem.php?pid=4027 分析:因为这个操作是把一个数变成平方根,所以显得略棘手,不过如果仔细演算的话会发现一个2^64数的 ...
- CodeForces - 589J —(DFS)
Masha has recently bought a cleaner robot, it can clean a floor without anybody's assistance. Schema ...