input单选框
css代码
#con{
overflow: hidden;
width: 220px;
position: relative;
}
.nan,
.nv{
width: 100px;
height: 60px;
background: #e3e3e3;
display: block;
float: left;
text-align: center;
line-height: 60px;
font-size: 20px;
color: white;
font-weight: 700;
}
#nan,
#nv{
display: none;
}
.active{
background: blue;
}
HTML代码
<div id="con">
<label for="nan" class="nan">男</label>
<input type="radio" name="sex" id="nan" value="1" />
<label for="nv" class="nv">女</label>
<input type="radio" name="sex" id="nv" value="0" />
</div>
<button class="btn">
提交
</button>
js代码
<script type="text/javascript">
$('.btn').click(function(){
var obj = {
sex:$("#con input[type=radio]:checked").val()
}
console.log($("#con input[type=radio]:checked").val())
})
$('#con label').click(function(){
$(this).addClass('active').siblings().removeClass('active')
})
</script>