自定义select

因为select 在个别android手机上不能兼容,所以自己写一个。

原理就是:1、点击input按钮显示弹出选择框,再点击选择框隐藏。

    2、input 的value就等于选择框里面选择的值。

    3、再把选择框隐藏。

html代码:

//点击的input按钮

<input type="button" id="zdy-butt" value="" />  

//选择框  

<div class="rule-bg" style="overflow: hidden;" id="where-color">
    <div class="rule-box"  id="where-color-onson">
       <ul class="where-classname default_list" style="color: #FFFF00;max-height: 300px;">
             <li class="form-control"><label>ccc</label><span><img src="img/j-select.png"/></span></li>
         <li class="form-control"><label>bbb</label><span><img src="img/j-select.png"/></span></li>
         <li class="form-control"><label>aaa</label><span><img src="img/j-select.png"/></span></li>
             <li class="form-control"><label>ddd</label><span><img src="img/j-select.png"/></span></li>
       </ul>
    </div>
</div>


js代码:

//点击按钮判断选择框状态是隐藏还是显示

       $("#zdy-butt").on("click", function() {
      var e = $("#where-color").css("display");
     "none" == e ? ($("#where-color").show()):($("#where-color").hide());
       });

//input 的值默认为第一个选择框的值
$(function(){
$("#zdy-butt").val($("#where-color-onson div div:eq(0)").children("label").text());
});

//input 的值等于下拉框选择的值
$("#where-color-onson ul li").on("click",function() {
$("#zdy-butt").val($("#where-color-onson ul li:eq("+$(this).index()+")").children("label").text());
setTimeout(hidecolor,500);

});

function hidecolor(){
$("#where-color").hide();
}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值