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

jquery实现上下箭头下拉框

时间:2014-11-24 14:59:57      阅读:150      评论:0      收藏:0      [点我收藏+]

标签:style   blog   io   ar   color   os   sp   for   on   

<html>
 <head></head>
 <body>
  <form class="select"> 
   <input type="text" value="3" id="am" class="am" readonly="" /> 
   <div class="icon"> 
    <div class="up"></div> 
    <div class="down"></div> 
   </div> 
   <div id="HMF-1" style="display: none " class="bm"> 
    <span class="cur">3</span> 
    <span class="cur">2</span> 
    <span class="cur">1</span> 
   </div> 
  </form>
 </body>
</html>

  css:

.select {
    min-width: 34px;
    position: relative;
    margin-top:2px;
    display: inline-block;
    display: -webkit-inline-box;
    border: 1px #999999 solid;
}

.cur {
    cursor: pointer;
    display: block;
    background:#fff;
    color:  #fd7602;
    height: 22px;
    line-height: 22px;
    padding-left:10px;
}

.cur:hover {
    background: #878787;
    color: #fff;
}

.am {
    border: 0px;
    color: #fd7602;
    cursor: pointer;
    width: 34px;
    height: 19px;
    padding-left: 10px;
}

.bm {
    position: absolute;
    border: 1px #999999 solid;
    width: 42px;
    margin-top: -21px;
    padding-top: 21px;
}

.icon {
    position: absolute;
    top: 0;
    right: 0;
    height: 19px;
    padding: 3px;
}

.icon div {
    width: 7px;
    height: 3px;
    cursor: pointer;
}

.icon .up {
    margin-top:2px;
    background:url(img/pop/jian.png) top center no-repeat;
}

.icon .down {
    margin-top:3px;
    background:url(img/pop/jian.png) bottom center no-repeat;
}

js:

 function selectFn(){
            var select_index=0;
            var _span=$(‘span.cur‘);
            var _am=$(‘#am‘);
            var _select_div=$(‘#HMF-1‘);

            $(‘span.cur‘).click(function(){
                select_index=$(this).index();
                _am.val($(this).html());
                _select_div.css(‘display‘,‘none‘);
                $(‘form.select‘).css(‘border‘,‘1px #999999 solid‘);
            });
            _am.click(function(){
                if(_select_div.css(‘display‘) ==‘none‘){
                    _select_div.css(‘display‘,‘block‘);
                   $(‘form.select‘).css(‘border‘,‘none‘);
                }
                else{
                    _select_div.css(‘display‘,‘none‘);
                    $(‘form.select‘).css(‘border‘,‘1px #999999 solid‘);
                }
            });
            $(‘div.up‘).click(function(){
                select_index = select_index >0 ? (select_index-1) : 0;
                _am.val(_span.eq(select_index).html());
            });
            $(‘div.down‘).click(function(){
                select_index = select_index <_span.length-1 ? (select_index+1) : select_index;
                _am.val(_span.eq(select_index).html());
            });
        }

 

jquery实现上下箭头下拉框

标签:style   blog   io   ar   color   os   sp   for   on   

原文地址:http://www.cnblogs.com/huanglifen/p/4118468.html

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