为了账号安全,请及时绑定邮箱和手机立即绑定

被选中的单选项修改样式

被选中的单选项修改样式

至尊宝的传说 2018-11-14 13:14:49
修改被选中的单选项的样式,但是添加了样式之后修改选项样式仍然存在,即同时出现两个被选中的样式,以下是我的代码,请问各位应该如何修改?
查看完整描述

1 回答

?
手掌心

TA贡献1942条经验 获得超3个赞

    <div class="choice">

        <label>

            <input type="radio" class="a" name="1"><span class="aFont">aaaaa</span>

        </label>

        <label>

            <input type="radio" class="b" name="1"><span class="bFont">bbbbb</span>

        </label>

        <label>

            <input type="radio" class="c" name="1"><span class="cFont">ccccc</span>

        </label>

        <label>

            <input type="radio" class="d" name="1"><span class="dFont">ddddd</span>

        </label>

    </div>

<script>

        $(document).ready(function(){

            $(".choice input[type = 'radio']").on("click",function(){

                if ($(".choice input:checked")){

                    $(this).parent().css("background" , "green").siblings().css("background","red");

                }

            });

        });

</script>

你选中的 是input 不是label 注意 $(this).parent().css("background","green").siblings()

查看完整回答
反对 回复 2018-12-08
  • 1 回答
  • 0 关注
  • 427 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号