一。网上(self测试)
<input type="radio" name="radio" value="1" />1<br/>
<input type="radio" name="radio" value="2" />2<br/><input type="radio" name="radio" value="3" />3<br/>
<input type="radio" name="radio" value="4" />4
<script type="text/javascript">
$("input[name='radio']").on("change",function(event) {
var a = $("input[name='radio']:checked").val();alert("选中的radio的值是:" + a);
});
</script>
二。项目中的:
<li>
<div class="fl titl">
情感状态
</div>
<div class="cont" id="love">
<div class="check_type fr">
<label><input type="radio" name="love" value="0" />公开</label>
<label><input type="radio" name="love" value="1" />圈子</label>
<label><input type="radio" name="love" value="2" />保密</label>
</div>
<select class="middle_item" name="loveVal" id="loveVal">
<option value="">请选择</option>
<option value="0">单身</option>
<option value="1">热恋中</option>
<option value="2">已婚</option>
<option value="3">离异</option>
</select>
</div>
</li>
//错误提示
function errorInfo(error){
$("#error").show().text(error);
setTimeout(function(){
$("#error").fadeOut();
},1000)
};
var oInfor = {};
if($('#love').find("input[name='love']").is(':checked')){
var loveCheckedVal = $('#love').find("input[name='love']:checked").val();
oInfor.loveCheckedVal = loveCheckedVal;
}else{
errorInfo('请选择情感状态的保密程度!');
return false;
};
$(".cont .check_type").find("label").on("click",function(){
var _this = $(this);
_this.find("input[type='radio']").attr('checked',true);
_this.addClass('cur').siblings('label').removeClass('cur');
_this.siblings('label').find("input[type='radio']").attr('checked',false);
});