被选中的单选项修改样式

修改被选中的单选项的样式,但是添加了样式之后修改选项样式仍然存在,即同时出现两个被选中的样式,以下是我的代码,请问各位应该如何修改?

https://img1.mukewang.com/5c0b70350001bec709350448.jpg

至尊宝的传说
浏览 428回答 1
1回答

手掌心

&nbsp; &nbsp; <div class="choice">&nbsp; &nbsp; &nbsp; &nbsp; <label>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <input type="radio" class="a" name="1"><span class="aFont">aaaaa</span>&nbsp; &nbsp; &nbsp; &nbsp; </label>&nbsp; &nbsp; &nbsp; &nbsp; <label>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <input type="radio" class="b" name="1"><span class="bFont">bbbbb</span>&nbsp; &nbsp; &nbsp; &nbsp; </label>&nbsp; &nbsp; &nbsp; &nbsp; <label>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <input type="radio" class="c" name="1"><span class="cFont">ccccc</span>&nbsp; &nbsp; &nbsp; &nbsp; </label>&nbsp; &nbsp; &nbsp; &nbsp; <label>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <input type="radio" class="d" name="1"><span class="dFont">ddddd</span>&nbsp; &nbsp; &nbsp; &nbsp; </label>&nbsp; &nbsp; </div><script>&nbsp; &nbsp; &nbsp; &nbsp; $(document).ready(function(){&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $(".choice input[type = 'radio']").on("click",function(){&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if ($(".choice input:checked")){&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $(this).parent().css("background" , "green").siblings().css("background","red");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; });&nbsp; &nbsp; &nbsp; &nbsp; });</script>你选中的 是input 不是label 注意 $(this).parent().css("background","green").siblings()
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript