自定义select下拉框,解决select下拉框在IE上的样式异常

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title></title>
    <link rel="stylesheet" href="content/font/iconfont.css">
    <style type="text/css">
        /*css*/
        /*通用样式*/
        body{
            /*background: #FFBD1E;*/
        }
        ul,li{
            list-style: none;
            padding: 0;
            margin: 0;
        }
        /*下拉框样式*/
        #select{
            margin:100px;
            background: rgba(0,0,0,0);
            width: 249px;
            height: 40px;
            font-family: "微软雅黑";
            color: #666;
            border: 1px #ccc solid;
            border-radius: 5px;
            box-shadow: 0 0 5px #ccc;
        }
        .select-head{
            overflow: hidden;
            width: 249px;
            height: 40px;
            box-sizing: border-box;
            padding: 0 10px;
            line-height: 40px;
        }
        .select-head .select-head-cont{
            float: left;
        }
        .select-head .select-icon{
            float: right;
            font-size: 14px;
        }
        .option{
            text-indent: 10px;
            margin-top: 1px;
            width: 249px;
            color: #666666;
            background: rgba(230,200,200,0.1);
            line-height: 35px;
            border: 1px #cfcfcf solid;
            display: none;
            box-shadow: 0 0 5px #ccc;
            font-size: 14px;
        }
        .option-item:hover{
            background: rgba(230,200,200,0.4);
            cursor: pointer;
        }
    </style>
</head>
<body>
<!--html-->
<ul id="select">
    <li>
        <div class="select-head">
            <span class="select-head-cont"></span>
            <span class="iconfont icon-xiala select-icon"></span>
        </div>
        <ul class="option">
            <li class="option-item">宋体</li>
            <li class="option-item">微软雅黑</li>
            <li class="option-item">黑体</li>
            <li class="option-item">方正</li>
        </ul>

    </li>
</ul>
<script type="text/javascript">
    //int
    var selectHead = document.getElementsByClassName('select-head')[0];
    var selectHeadCont = document.getElementsByClassName('select-head-cont');
    var Option = document.getElementsByClassName('option')[0];
    var optionItem = document.getElementsByClassName('option-item');

    /*默认是第一个选项*/
    selectHeadCont[0].innerHTML = optionItem[0].innerHTML;

    /*点击后出现下拉框*/
    selectHead.addEventListener('click',function(e){
        e.stopPropagation();
        Option.style.display = 'block';
    },false);
    /*点击选项后出现在下拉框*/
    var len = optionItem.length;
    for(var i=0;i<len;i++){
        optionItem[i].index = i;
        optionItem[i].addEventListener('click',function(){
            selectHeadCont[0].innerHTML = optionItem[this.index].innerHTML;
            Option.style.display = 'none';
        },false);
    }
    // /*点击其他地方时,select会收起来*/
    document.body.addEventListener('click',function(){
        Option.style.display = 'none';
    },false);
</script>
</body>
</html>

 

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值