84669 人が学習中
152542 人が学習中
20005 人が学習中
5487 人が学習中
7821 人が学習中
359900 人が学習中
3350 人が学習中
180660 人が学習中
48569 人が学習中
18603 人が学習中
40936 人が学習中
1549 人が学習中
1183 人が学習中
32909 人が学習中
選択した 1 つのオプションのスタイルを変更しますが、スタイルを追加した後も、変更したオプション スタイルはまだ存在します。つまり、選択した 2 つのスタイルが同時に表示されます。以下は私のコードです。どのように変更すればよいですか?
小伙看你根骨奇佳,潜力无限,来学PHP伐。
<p 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> </p> <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()
代码没测试, 思路就是先移除所有背景色,再给点击的那一个添加背景色, 你这个if判断是不需要的
<script> $(document).ready(function(){ $(".choice input[type = 'radio']").on("click",function(){ $(".choice input[type = 'radio']").css("background",""); $(this).css("background","red"); }); }); </script>
你选中的 是input 不是label 注意 $(this).parent().css("background","green").siblings()
代码没测试, 思路就是先移除所有背景色,再给点击的那一个添加背景色, 你这个if判断是不需要的