码迷,mamicode.com
首页 > Web开发 > 详细

ul+js模拟select+改进

时间:2014-12-19 18:57:27      阅读:132      评论:0      收藏:0      [点我收藏+]

标签:

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");
    }
  })

 

ul+js模拟select+改进

标签:

原文地址:http://www.cnblogs.com/jymz/p/4174511.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!