HTML
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta content="width=device-width, initial-scale=1,maximum-scale=1, user-scalable=no" name="viewport" />
<script src="js/jquery.min.js"></script>
<style type="text/css">
body {
font: 14px/150% microsoft yahei,tahoma;
}
.MyInputStyle input {
display: none;
}
.MyInputStyle label {
border: 1px solid #CCC;
color: #666;
padding: 2px 10px 2px 5px;
line-height: 28px;
min-width: 80px;
text-align: center;
float: left;
margin: 2px;
border-radius: 4px
}
.MyInputStyle input:checked + label {
background: url(img/ico_checkon.svg) no-repeat right bottom;
border: 1px solid #00a4ff;
background-size: 21px 21px;
color: #00a4ff
}
.MyInputStyle input:disabled + label {
opacity: 0.7;
}
</style>
<title>纯CSS input/checkbox-radio 美化</title>
</head>
<body>
<p>请选择友商(加上name属性就是单选框(必须),去掉则是多选框,id是必须属性,class属性为了点击事件加的)</p>
<div class="MyInputStyle">
<input type="radio" name="company" id="dealer1" value="huawei"/>
<label for="dealer1">华为</label>
<input type="radio" name="company" id="dealer2" value="xiaomi"/>
<label for="dealer2">小米</label>
<input type="radio" name="company" id="dealer3" value="tengxun"/>
<label for="dealer3">腾讯</label>
<input type="radio" name="company" id="dealer4" checked value="alibaba"/>
<label for="dealer4">阿里</label>
</div>
<br/>
<br/>
<p>选择兴趣爱好</p>
<div class="MyInputStyle">
<div class="Block PaddingL">
<input type="checkbox" id="hobby1" class="hobby" value="java"/>
<label for="hobby1">Java</label>
<input type="checkbox" id="hobby2" class="hobby" value="html"/>
<label for="hobby2">HTML</label>
<input type="checkbox" id="hobby3" class="hobby" value="python"/>
<label for="hobby3">Python</label>
<input type="checkbox" id="hobby4" checked class="hobby" value="c++"/>
<label for="hobby4">C++</label>
</div>
</div>
<br/>
<br/>
<input type="button" id="demo" value="获取选择的值"/>
<br/>
<br/>
<p>禁止属性</p>
<div class="MyInputStyle">
<div class="Block PaddingL">
<input type="checkbox" id="bare" checked disabled />
<label for="bare">秃头</label>
<input type="checkbox" id="hair" disabled />
<label for="hair">长发</label>
</div>
</div>
<script>
$("#demo").click(function(){
var singleVal = $("input[name='company']:checked").val();
var doubleVal=new Array();
$(".hobby:checked").each(function(){
doubleVal.push($(this).val());
});
alert("单选值:【"+singleVal+"】===多选值:【"+doubleVal+"】");
});
</script>
</body>
</html>
效果图
图片
图片素材链接下载