更改bg无线电取消选择 [英] Change bg on radio deselect

查看:87
本文介绍了更改bg无线电取消选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这只是对我的最后一个问题的补充。一旦我取消选择单选按钮,我需要返回背景颜色到其原始状态。所以我们想出的解决方案是:

This is just an add on to my last question. Once I deselect the radio button I need to return the background color to its original state. So the solution we came up with is:

$(document).ready(function(){
    $('input:radio').change(function(){
        $(this).closest('div').toggleClass('highlight');
    });
});

现在,当单选按钮取消选择时,我需要删除突出显示类 - 任何想法?

Now I need to remove the highlight class when the radio button is deselected - any ideas?

推荐答案

尝试这样,使用name属性分组收音机,以下js应该工作

Try this, group your radios using the name attribute and the following js should work

演示

 $('input:radio').change(function(){
        $('div.highlight').removeClass('highlight');
        $(this).closest('div').addClass('highlight');
 });

这篇关于更改bg无线电取消选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆