css模拟下拉菜单

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>css模拟下拉菜单</title>
    <style>
        * {
            padding: 0;
            margin: 0;
        }
        ul {
            list-style: none;
        }
        #select {
            margin: 30px auto;
            width: 200px;
        }
        #input {
            width: 100%;
            line-height: 18px;
            outline: none;
            box-sizing: border-box;
            border-radius: 8px;
            border: 1px solid #ccc;
            padding: 0 8px;
        }
        #input:focus {
            box-shadow: 0 0 5px blue;
        }
        #list {
            display: none;
            border: 1px solid #ccc;
            box-sizing: border-box;
            width: 100%;
            border-bottom: none;
        }
        #list li {
            padding: 6px 4px;
            border-bottom: 1px solid #ccc;
        }
    </style>
    <script type="text/javascript" src="conn.js"></script>
    <script>
        window.onload = function () {
            var
                oInput = $('input'),
                oList = $('list'),
                aLi = oList.children;
            oInput.onfocus = function () {
                oList.style.display = 'block';
            }
            //给每个LI添加click事件
            for (var i = 0; i < aLi.length; i++) {
                aLi[i].onclick = function () {
                    oInput.value = this.innerHTML;
                }
            }
            oInput.onblur = function () {
                setTimeout(function () {
                    oList.style.display = 'none';
                },200);
            }
        }
    </script>
</head>
<body>
    <div id="select">
        <input type="text" id="input">
        <ul id="list">
            <li>食品</li>
            <li>汽车</li>
            <li>衣服</li>
            <li>珠宝</li>
            <li>化妆品</li>
        </ul>
    </div>
</body>
</html>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值