2015-06-16 40 views
-2

在我的HTML代碼,我有2個複選框陣列,如同下列的問題選中時,ToolI中具有相同索引的複選框變爲啓用狀態。與複選框陣列[JS和jQuery]

+0

除了缺乏研究工作,這個問題本身似乎罰款。這當然不是不清楚或者**太寬** – CodingIntrigue

+0

我找到了一些信息,但是以一種非常不同的方式使用了DOM,這讓我很困惑 –

回答

1

查看評論內嵌代碼:

// Bind change event to all the elements having name as taski[] 
$('[name="taski[]"]').on('change', function() { 
    // If this checkbox is checked then disable the next checkbox to this 
    $(this).next(':checkbox').prop('disabled', !$(this).is(':checked')); 


    // OR 
    $(this).next(':checkbox').prop('disabled', !this.checked); 
}); 

演示:http://jsfiddle.net/tusharj/j35xk2ep/

演示:http://jsfiddle.net/80L44fjx/(感謝@RGraham)

+1

您也可以訪問標準'checked'屬性:http:// jsfiddle .NET/80L44fjx / – CodingIntrigue