2012-11-01 47 views
0

在解决此问题时遇到了一些麻烦。如果第二个和第三个td中的复选框都未选中,则禁用第四个中的复选框。如果没有选中某个复选框,请执行某些操作

$('#allergies tbody tr').each(function() { 
    if ($('td:eq(1) input[type="checkbox"]:not(:checked)', $(this)).length > 0 
     && $('td:eq(2) input[type="checkbox"]:not(:checked)', $(this)).length > 0) { 
     $("td:eq(3) input", $(this)).attr('disabled', false); 
    } 
}); 
+0

具体的人是的,我是智障者并将false设置为禁用而不是true。 – ediblecode

回答

1
$('#allergies tbody tr').each(function() { 
    if ($('td:eq(1) input[type="checkbox"]:not(:checked)').length > 0 
     && $('td:eq(2) input[type="checkbox"]:not(:checked)').length > 0) { 
     $("td:eq(3) input").prop('disabled', true); 
    } 
}); 

于TR使用

$('#allergies tbody tr').each(function() { 
    if ($('td:eq(1) input[type="checkbox"]:not(:checked)', $(this)).length > 0 
     && $('td:eq(2) input[type="checkbox"]:not(:checked)', $(this)).length > 0) { 
     $("td:eq(3) input", $(this)).prop('disabled', true); 
    } 
}); 
0

你的逻辑是正确的,但不易阅读.. 它们分开成小块

$('#allergies tbody tr').each(function() { 
    var $this = $(this); 
    var chk1 = $this.find('td:eq(1) input[type="checkbox"]').is(':checked'); 
    var chk2 = $this.find('td:eq(2) input[type="checkbox"]').is(':checked'); 

    // If both are false then disable else 
    // enable them 
    if(chk1 === false && chk2 === false){ 
     $this.find('td:eq(3) input').prop('disabled', true); 
    } 
    else{ 
     $this.find('td:eq(3) input').prop('disabled', false); 
    } 
}); 
相关问题