2012-03-01 56 views

回答

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'); 
    } 
}); 
+0

驚人的,非常感謝!現在是時候解決我的頭痛! – user1243801 2012-03-01 21:57:39