zoukankan      html  css  js  c++  java
  • 模仿select选择框

    Css:

    .CustomSearch{position:relative;background:#fff; width:170px;}
     .CustomSearch .title{ cursor:pointer; height:20px; line-height:20px;*line-height:22px;overflow:hidden; padding-left:5px; }
    .CustomSearch .title em{ float:right; margin:7px 10px 0 0; display:block;width:10px; height:10px; background: url(../images/cssPos/custom_last_bg.jpg) no-repeat -65px -85px;}
    .CustomSearch ol{ position:absolute; display:none;width:170px; background:#eee;}
    .CustomSearch ol li{ float:none; margin:0; padding-left:5px; cursor:pointer; height:25px; line-height:25px; }
    .CustomSearch ol li:hover{ background:#cfcbca; color:#fff;}

    DOM:

    <div class="CustomSearch">
        <div class="title">
              <em></em>
              <span>选择类别:</span>
              <span class="text">戒指&nbsp;&nbsp;吊坠</span>
              <input type="hidden" value="0" />
        </div>
        <ol class="clearfix">
            <li code="1">戒指</li>
            <li code="2">项链</li>
            <li code="3">手链</li>
            <li code="4">耳钉</li>
        </ol>
    </div>

    JS:

    function CustomSearch(obj){
        this.CustomSearch=$(obj);//保存单个控件
        this.innerText=$(".text",this.CustomSearch);//保存准备改变文本的节点
        this.input=$("input",this.CustomSearch);//保存隐藏域
        this.select=$("ol",this.CustomSearch);//保存下拉框
        this.options=$("li",this.CustomSearch);//保存下拉选项
        this.t=null;
        var _this=this;
        this.CustomSearch.click(function(){
                                    _this.select.show();     
                                         }).mouseout(function(){
                                             _this.t=window.setTimeout(function(){
                                                                                _this.select.hide();
                                                                                },100);
                                                
                                             }).mouseover(function(){
                                                 window.clearTimeout(_this.t);
                                                 });
        this.options.click(function(e){
                                    e.stopPropagation();
                                    var i=$(this).index();
                                    _this.setValue(i);
                                    _this.select.hide();
                                    });
        };
    CustomSearch.prototype={
        setValue:function(i){
            this.innerText.text(this.options.eq(i).text());
            this.input.val(this.options.eq(i).attr("code"));
            }
        
        };
    CustomSearch.inite=function(CustomSearchs){
        var _this_=this;
        CustomSearchs.each(function(){
                                    new _this_(this);
                                    });
        };

    调用:

    CustomSearch.inite($(".CustomSearch"));
  • 相关阅读:
    nyoj 164&amp;&amp;poj2084 Game of Connections 【卡特兰】
    1、Cocos2dx 3.0游戏开发找小三之前言篇
    hibernate一级缓存,二级缓存和查询缓存
    WCF服务端调用client.
    优化中的subgradient方法
    Xsolla和Crytek合作,对游戏战争前线推出全新支付方式
    CNZZ站点流量统计原理简析
    分数加减法
    【jvm】windows下查看java进程下多线程的相关信息
    【面试 docker+k8s+jenkins】【第二十篇】docker+k8s+jenkins相关面试
  • 原文地址:https://www.cnblogs.com/yangliulang/p/2716426.html
Copyright © 2011-2022 走看看