多个单选框 input type="radio"选中效果

一。网上(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);
    });


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值