js/jq两组单选框关联起来,点击一组,另一组随第一组一起变化(判断单选选中未选中)

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <script type="text/javascript" src="js/jquery-1.12.4.min.js"></script>
</head>
<body>
    <table>
        <tr>             
                <td>密码</td>
                <td>
                    <input type="radio" id="inputPassYes" name="passwordRequire" value="1">是
                    <input type="radio" id="inputPassNo" name="passwordRequire" value="0">否
                </td>    
            </tr>
            <tr>
                <td>确认密码</td>
                <td>
                    <input type="radio"  id="inputConfirmYes" name="confirmPasswordRequire" value="1" disabled>是
                    <input type="radio"  id="inputConfirmNo" name="confirmPasswordRequire" value="0" disabled>否
                </td>  
            </tr>
    </table>
</body>
<script type="text/javascript">
        /**
        *页面刚加载进去判断是否选中
        */
        if ($("#inputPassYes").attr("checked")){
            $("#inputConfirmYes").attr("checked","checked");
            // console.log('选中')
        }
        if ($("#inputPassNo").attr("checked")){
            $("#inputConfirmNo").attr("checked","checked");
            // console.log('未选中')
        }
        /**
        *点击的时候进行关联选中
        */

        $("#inputPassYes").on('click',function () {
            $("#inputConfirmYes").prop("checked","checked");//刚开始用的是attr,怎奈何死都无法实现想要的效果,换成prop就可以达到效果了,知道为什么的各位大神可以评论为我解惑
            // $("input:radio[name='confirmPasswordRequire']").eq(0).prop("checked","checked");//此方法也可以用
        })
        $("#inputPassNo").on('click',function () {
            $("#inputConfirmNo").prop("checked","checked");
            // $("input:radio[name='confirmPasswordRequire']").eq(1).prop("checked","checked");
        })

</script>
</html>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值