运行代码 缩小
坏蛋
HTML代码
复制 格式化 注释 注释 清空
放大
x
 
1
<!DOCTYPE html>
2
<html>
3
    <head>
4
        <meta content="text/html;charset=utf-8" http-equiv="Content-Type" />
5
        <script type="text/javascript" src="//apps.bdimg.com/libs/jquery/1.11.3/jquery.min.js">
6
        </script>
7
    </head>
8
    <body>
9
        <div class="input-box">
10
            <input type="text" class="input" value="Holle Word" />
11
            <span class="tip-l">
12
            </span>
13
            <ul class="dropdown">
14
                <li>Holle Word
15
                </li>
16
                <li>这是一个测试
17
                </li>
18
                <li>简单的dome
19
                </li>
20
            </ul>
21
        </div>
22
    </body>
23
</html>
24
CSS代码
复制 格式化 注释 注释 颜色 清空
放大
xxxxxxxxxx
58
 
1
.input-box {
2
  position: relative;
3
  display: inline-block;
4
}
5
.input-box input {
6
  background-color: transparent;
7
  background-image: none;
8
  border: 1px solid #ccc;
9
  border-radius: 4px;
10
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.075) inset;
11
  color: #555;
12
  display: block;
13
  font-size: 14px;
14
  line-height: 1.42857;
15
  padding: 6px 6px;
JS代码
复制 格式化 注释 注释 清空
放大
xxxxxxxxxx
27
 
1
$(function(){
2
    var isBox = false;
3
    $(".dropdown").hide();
4
5
    $(".input").focus(function () {
6
      $(this).siblings(".dropdown").show();
7
      isBox = true;
8
    });
9
    $(".input-box").mousemove(function () {
10
      isBox = true;
11
    });
12
    $(".input-box").mouseout(function () {
13
      isBox = false;
14
    });
15
    $(".input").blur(function () {
16
      if (isBox == true) return false;
17
      $(this).siblings(".dropdown").hide();
18
    });
19
    $(".dropdown").find('li').each(function () {
20
      $(this).on("click", function () {
21
        isBox = false;
22
        var text = $(this).text();
23
        $(this).parent().siblings(".input").val(text);
24
        $(this).parent().hide();
25
      })
26
    })
27
});
名称
jQuery input 下拉框焦点事件
分类
jQuery实例
描述
收藏