自定义单选按钮

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        .radio{
            display: flex;
            align-items: center;
            width: 100px;
            cursor: pointer;
        }
        .yuan{/*大圈*/
            display: block;
            width: 10px;
            height: 10px;
            border-radius: 50%;
            background: #ececec;/*这里写自己喜欢的颜色*/
            display: flex;
            align-items: center;
            margin-right: 5px;
        }
        .radio>span.rdactive{
            background: #EF6121;/*这里写自己喜欢的颜色*/
        }
        .yuan span{/*小圈*/
            display: block;
            width: 4px;
            height: 4px;
            border-radius: 50%;
            background: white;/*这里写自己喜欢的颜色*/
            margin: 0 auto;
        }
    </style>
    <script src="js/jquery-1.11.3.js"></script>
</head>
<body>
    <div class="radio"><span class="yuan rdactive"><span></span></span>你丑你先</div>
    <div class="radio"><span class="yuan"><span></span></span>你才丑你先</div>
    <div class="radio"><span class="yuan"><span></span></span>你更丑你先</div>
    <script>
        $(".radio").children('.yuan').on('click',function(){
            $('.rdactive').removeClass('rdactive');
            $(this).addClass("rdactive").siblings().removeClass("rdactive");
        })
    </script>
</body>
</html>

猜你喜欢

转载自blog.csdn.net/weixin_36302575/article/details/85156656