0

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

这是我正在使用的代码:

http://jsfiddle.net/ceWbW

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

4

1 回答 1

0

$("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');
    }
});
于 2012-03-01T21:45:59.573 回答