zoukankan      html  css  js  c++  java
  • 封装下拉列表,替换select和option

    option不能设置高度和样式,封装一个下拉列表替换select和option

    <!doctype html>
    <html lang="en">
    <head>
    <meta charset="UTF-8">
    <meta name="viewport"
    content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
    .divInput{
    200px;
    height: 40px;
    line-height: 40px;
    margin: 100px auto;
    }
    .inputBox{
    100%;
    height: 100%;
    border: 1px solid #cccccc;
    position: relative;
    }
    .inputBox div{
    100%;
    padding: 0 10px;
    box-sizing: border-box;
    }
    .inputBox img{
    position: absolute;
    right: 34px;
    top: 48%;
    }
    .list{
    100%;
    border: 1px solid #cccccc;
    box-shadow: 0 0 10px #999;
    }
    .list ul{
    padding: 0;
    margin: 0;
    }
    .list ul li{
    padding-left: 10px;
    list-style: none;
    100%;
    height: 30px;
    line-height: 30px;
    cursor: pointer;
    box-sizing: border-box;

    }
    .list ul li:first-child{
    color: #999;
    }
    .list ul li.active{
    background-color: #226ebc;
    color: #fff;
    }
    .list ul li:hover{
    background-color: #226ebc;
    color: #fff;
    }
    </style>
    </head>
    <body>


    // chooseGender 是灵活添加的类名,用于调用js,当页面多处需要使用下拉列表,这个类名不一样
    <div class="divInput chooseGender">
    <div class="inputBox">
    <div>筛选实验类型</div>
    <img src="../assets/arrow.png" alt=""> // 下拉图片
    </div>
    <div class="list" style="display: none;">
    <ul>
    <li>请选择</li>
    <li>男</li>
    <li>女</li>
    </ul>
    </div>
    </div>



    <script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>

    <script>


    function xiaLaChooseItem(jQueryTag){

    jQueryTag.parent().css({
    position: 'relative'
    })

    jQueryTag.find('.inputBox').click(function () {
    if (jQueryTag.find('.list:hidden')[0] === undefined) {
    jQueryTag.find('.list').hide()
    } else {
    jQueryTag.find('.list').show()
    }
    })

    jQueryTag.find('.list>ul>li').click(function () {
    var value = $(this).text()
    jQueryTag.find('.inputBox>div').text(value)
    $(this).addClass('active').siblings().removeClass('active')
    jQueryTag.find('.list').hide()
    })
    }

    xiaLaChooseItem($('.chooseGender'))

    </script>
    </body>
    </html>
    
    
  • 相关阅读:
    Atitit 常用比较复杂的图像滤镜 attilax大总结
    Atitit usrQBM1603短信验证码规范
    Atitit usrQBM2331 参数格式化规范
    Atitit 函数式编程与命令式编程的区别attilax总结  qbf
    atitit 短信接口规范与短信解决方案.docx
    atitit  验证码理论与概览与 验证码规范 解决方案.docx
    Atiti  attilax主要成果与解决方案与案例rsm版 v4
    Atitit 作用域的理解attilax总结
    Atitit cms
    Atitit 图片 验证码生成attilax总结
  • 原文地址:https://www.cnblogs.com/xushan03/p/15184856.html
Copyright © 2011-2022 走看看