Q: How to enable/disable input with checkbox?
Each checkbox enable/disable input next to it. Number of groups is various (i = 1,2,3, ...n).
Default setting is that inputs are disabled and checkbox unchecked.
HTML:
JS:
$("input[name="group1"][type="checkbox"]").click(function() {
$("input[name="name11"][type="text"]").attr("disabled", !this.checked);
$("input[name="name12"][type="text"]").attr("disabled", !this.checked);
$("input[name="name13"][type="text"]").attr("disabled", !this.checked);
});
解决方案
You need to write a change() handler for the checkboxes and then use nextUntil() to find out the input fields to be disabled
$('input[type="checkbox"]').change(function(){
$(this).nextUntil(':not(input:text)').prop('disabled', !this.checked)
}).change()