【问题标题】:jQuery toggle class of label when radio button is clicked单击单选按钮时jQuery切换标签类
【发布时间】:2011-11-10 21:11:54
【问题描述】:

我的单选按钮周围有一个标签,背景应该在 :hover 和 :focus 上改变

<label for="radio1" class="radio-blur">
<input name="job" id="radio1" value="1" type="radio"> Graphic Design</label>

我想将课程从 .radio-blur 更改为 .radio-focus

我有

    $(document).ready(function(){
        $('input:radio').click(function() {
            $(this).parent('label').toggleClass('.radio-focus');
        });  
    }); 

但它不起作用......请帮助

【问题讨论】:

    标签: jquery radio-button label toggleclass


    【解决方案1】:

    去掉类中的点

    $(this).parent('label').toggleClass('radio-blur radio-focus');
    

    JSFiddle

    【讨论】:

    • 您也要删除 .radio-blur 吗?
    • 是的,我想交换类,以便 .radio-focus 代替 .radio-blur
    • 我们可以用淡化效果切换类吗
    • 这个函数可以让你改变类属性。在它之后使用 fadeIn/Out 函数。
    猜你喜欢
    • 1970-01-01
    • 2011-05-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-22
    • 2020-05-20
    • 1970-01-01
    • 2012-12-13
    相关资源
    最近更新 更多