玲儿灵

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

html:

<div class="select_box">
                        <input type="text" value="还款方式" readonly="readonly">
                        <ul class="select_ul cur" style="display: none;">
                          <li class="sel_value">所有还款方式</li>
                          <li class="sel_value">等额本息</li>
                          <li class="sel_value">等额本金</li>
                          <li class="sel_value">到期还本付息</li>
                          <li class="sel_value">按月付息到期还本</li>
                          <li class="sel_value">一次付息到期还本</li>
                        </ul>
                      </div>

css:

/*模拟select*/
.select_box{
  float: left;
}
.select_box input{
  width: 160px;
  height: 30px;
  text-align: center;
  font-size: 18px;
  color: #444;
}
.select_ul{
  font-size: 14px;
  text-align: center;
  border: 1px solid #D2D3D3;
  position: absolute;
  top:29px;
}
.select_ul li{
  height: 50px;
  line-height: 50px;
}
.select_ul.cur li:hover{
  background-color: #4EC0EC;
}

js:

  //模拟select
  $(".select_box input").click(function(){
    var thisinput=$(this);
    var thisul=$(this).parent().find("ul.select_ul");
    if(thisul.css("display")=="none"){
//        if(thisul.height()>200){thisul.css({height:"200"+"px","overflow-y":"scroll" })};
      thisul.fadeIn("100");
      thisul.hover(function(){},function(){thisul.fadeOut("100");})
      thisul.find("li.sel_value").on('click',function(event){
        alert($(event.target).text());
        thisinput.val($(this).text());thisul.fadeOut("100");}).hover(function(){$(this).addClass("hover");},function(){$(this).removeClass("hover");});
    }
    else{
      thisul.fadeOut("fast");
    }
  })

 

posted on 2014-12-19 18:02  玲儿灵  阅读(299)  评论(0编辑  收藏  举报