Jquery结合css写开关按钮,拨动开关

19 篇文章 0 订阅

Jquery结合css写的开关

 

效果 

 

CSS

 

.choose-btn2 { display: none; }
.choose-label2 { box-shadow: #b1b1b1 0px 0px 0px 1px; width: 52px; height: 26px; display: inline-block; border-radius: 16px; position: relative; background-color: #bdbdbd; overflow: hidden; margin: 0; margin-top: 11px; cursor: pointer; vertical-align: middle; }
.choose-label2:before { content: ''; position: absolute; left: 4px;top:5px; width: 16px; height: 16px; display: inline-block; border-radius: 20px; background-color: #fff; z-index: 20; -webkit-transition: all 0.2s; transition: all 0.2s; }
.choose-btn2:checked + label.choose-label2:before { left: 31px; }
.choose-btn2:checked + label.choose-label2 { background-color: #009cef; box-shadow: #009cef 0px 0px 0px 1px; }
.choose-text2 { display: inline-block; vertical-align: middle; line-height: 20px; color: #666666; font-size: 12px; margin-top: 11px; }

 

 

Html

<div>
    <input type="checkbox"  id="switch2" class="choose-btn2" data-toggle="是|否">
    <label for="switch2" class="choose-label2"></label>
    <span class="choose-text2"></span>
</div>
<input type="text" style="display: none;" name="itemMain.IsGradePriceSetted"    id="isset" />

Js 

  $(".choose-btn2").click(function(){
    var texts = $(this).attr('data-toggle').split('|');
    $(this).siblings('.choose-text2').text(this.checked?texts[0]:texts[1]);
    $("#isset").val(this.checked?'Y':'N');
});
$(".choose-btn2").on("change", function(){
    var texts = $(this).attr('data-toggle').split('|');
    $(this).siblings('.choose-text2').text(this.checked?texts[0]:texts[1]);
    $("#isset").val(this.checked?'Y':'N');
});

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值