【问题标题】:Styling radio button label inside just one table row仅在一个表格行内设置单选按钮标签的样式
【发布时间】:2015-02-17 07:19:56
【问题描述】:

事情是这样的,我有一个包含多行单选按钮的表格,我想实现这个:

当我选中一个单选按钮时,相邻的标签会改变颜色,而该单行中的所有其他标签都会失去颜色。

现在我关闭了,但我缺少一些 jquery 技能来正确删除同一行的其他单选按钮上的颜色。

这是小提琴,价值超过千字。非常感谢任何帮助。

http://jsfiddle.net/cos33qvk/

Javascript:

$('input:radio').change(function(){
    if($('input:radio').is(":checked")) {
        $(this).parent().find('label i').addClass("on");
    } else {
        $(this).parent().find('label i').removeClass("on");
    }
});

【问题讨论】:

    标签: javascript jquery radio-button label styling


    【解决方案1】:
    $('input:radio').change(function() {
        // remove color properly on other radio buttons
        $(this).parents('tr').find('td label i').removeClass("on");
    
        // add class for current label
        if ($('input:radio').is(":checked")) {
            $(this).parent().find('label i').addClass("on");
        }
    });
    

    演示:http://jsfiddle.net/cos33qvk/2/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-06-06
      • 2010-09-07
      • 1970-01-01
      • 2019-01-25
      • 2011-06-06
      • 1970-01-01
      • 2013-05-17
      • 1970-01-01
      相关资源
      最近更新 更多