【问题标题】:Jquery - Removing class on CHECKED/UNCHECKED RADIO BUTTONSJquery - 删除 CHECKED/UNCHECKED RADIO BUTTONS 上的类
【发布时间】:2012-03-01 21:43:41
【问题描述】:

我已经为此苦苦挣扎了 5 个小时,我在这里上下搜索。我正在尝试更改包含 CHECKED RADIO 的 TABLE CELL 背景。 我设法添加了背景类,但未选中时我无法删除它的背景。

这是我正在使用的代码:

http://jsfiddle.net/ceWbW

在取消选中收音机后无论如何要删除背景类?我没能做到。 谢谢!

【问题讨论】:

    标签: jquery checked unchecked


    【解决方案1】:

    $("td input:not(:checked)") 仅将事件绑定到未选中的元素。

    将其绑定到所有td input 元素并在回调中使用this.checked 来访问选中状态。

    这是一个例子:http://jsfiddle.net/ceWbW/5/

    $("td input").change(function () {
        var $this = $(this);
        var td = $this.parent();
        // un-green all columns which contain a radio element from the same group
        td.siblings().filter(function() {
            return !!$(this).find('input[name="'+$this.attr('name')+'"]:radio').length;
        }).removeClass('green');
        // green the current column in case the radiobox is enabled
        if(this.checked) {
            td.addClass('green');
        }
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-01
      • 1970-01-01
      • 2015-09-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多