radio样式的写法,单选和多选如何快速的改变默认样式,纯CSS,

一。纯CSS写法改变单选框的默认选择样式,用背景图片代替

input[type='radio']:radio:before {
content: '';//这里需要有
width: 20px;
height: 20px;
display: inline-block;
background-image: url(img/lzw_check.png);//你要改变的样式图片
background-color: #2398f8;
background-size: cover;
border-radius: 10px;
}

因为ionic中的radio是完全是用初始化的样式的,理论上是同样适用的,暂时还未做尝试,博客持续更新

 

二。还有一种是用JS代码来实现

html

<div>
  <input type="radio" id="nba" checked="checked" name="sport" value="nba"> <label name="nba" class="checked" for="nba">NBA</label> <input type="radio" id="cba" name="sport" value="cba"> <label name="cba" for="cba">CBA</label> </div>

css

input[type="radio"] {
  margin: 3px 3px 0px 5px; display: none; } label { padding-left: 20px; cursor: pointer; background: url(bg.gif) no-repeat left top; } label.checked { background-position: left bottom; }
js
$(function() { $('label').click(function(){ var radioId = $(this).attr('name'); $('label').removeAttr('class') && $(this).attr('class', 'checked'); $('input[type="radio"]').removeAttr('checked') && $('#' + radioId).attr('checked', 'checked'); }); });
这办法是别人打代码,自己没尝试过,附上地址链接

https://segmentfault.com/q/1010000000521764

转载于:https://www.cnblogs.com/ChineseLiao/p/7410377.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值