<html>
<head>
<style>
.radio{
top: 12px;
position: absolute;
background-image: url("./icon.png");
background-color: #00A5E3;
width: 18px;
height: 18px;
background-position: -1px -260px;
background-repeat: no-repeat;
}
.radioavtive{
background-position: -77px -260px;
}
.box{
display: flex;
}
.box input{
z-index: 10;
}
</style>
</head>
<body>
<div class="box">
性别:
<div>
<div class="radio" id="sex">
</div>
<input style="opacity: 0" type="radio" name="sex" value="1" onclick="show(0)">男
</div>
<div >
<div class="radio" style="">
</div>
<input style="opacity: 0" type="radio" name="sex" value="1" onclick="show(1)">女
</div>
</div>
<!--<div class="radio" >-->
<!--<input style="opacity: 0" type="radio" name="sex" value="1" οnclick="show()">男-->
<!--</div>-->
<!--<div class="radio">-->
<!-- <input style="opacity: 0" type="radio" name="sex" value="2" οnclick="show()">女-->
<!--</div>-->
</body>
<script>
function show(type)
{
// alert(1);
var item = document.getElementsByClassName('radio')
console.log(item)
item[0].className = "radio"
item[1].className = "radio"
item[type].className = "radio radioavtive"
// item.setAttribute("class","rediocheck");
}
</script>
</html>
效果:
附件图片: