您的位置:首页 > Web前端 > CSS

radio单选框checkbox复选框新样式 更改原生样式 toggle toggleClass hasClass

2017-05-03 16:31 561 查看


<label class="sendType checked">白片</label>
<label class="sendType">蜡块</label>


.sendType {
background: url(../img/uncheck.png) no-repeat;
background-position: 0px 12px;
}
.checked {
background: url(../img/checked.png) no-repeat;
background-position: 0px 12px;
}
.myi_sjsq_table label{
cursor: pointer;
display: inline-block;
width: 70px;
text-indent: 20px;
}


$(document).ready(function(){
$(this).toggleClass("checked");
})




<label class="serSex checked">常规录入模式</label>
<label class="serSex">极简拍照模式</label>


.serSex {
background:url(../img/radio_unchecked.png) no-repeat scroll 0 0;
background-position: 0px 10px;
}
.checked {
background:url(../img/radio_checked.png) no-repeat scroll 0 0;
background-position: 0px 10px;
}
label {
text-indent: 25px;
cursor: pointer;
display: inline-block;
width: 180px;
}


$(document).ready(function(){
var modeChoose = "常规录入模式";
$(".serSex").click(function(){
$("#mode .serSex").removeClass("checked");
$(this).addClass("checked");
modeChoose = $(this).html();
})
})




<link href="//netdna.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css" rel="stylesheet">

<div class="col-md-8">
<label>
<input id="male" name="form-field-radio1" checked="checked" class="ace" onclick="javascript:document.getElementById('si_s_sex').value = '男'" autocomplete="off" type="radio">
<span class="lbl"> 男</span>
</label>
<label>
<input id="female" name="form-field-radio1" class="ace" onclick="javascript:document.getElementById('si_s_sex').value = '女'" autocomplete="off" type="radio">
<span class="lbl"> 女</span>
</label>
</div>


tipS:

判断是否含有某个样式

$("p").hasClass("another");
$("p").is(".another");//is("."+class);


切换样式

toggleBtn.toggle(function(){
//元素显示 代码③
}, function(){
//元素隐藏 代码④
})

toggleClass(class):如果存在(不存在)就删除(添加)一个类
$("p").toggleClass("another");
//重复切换类名“another”
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息