Disable input field when checkbox toggled (JQuery)

后端 未结 2 1135
天命终不由人
天命终不由人 2021-01-23 08:13

I have a list of checkboxes and with every checkbox, there is an input field. If I check the checkbox, the inputfield has to be disabled. Example:

Checkbox 1 -          


        
2条回答
  •  隐瞒了意图╮
    2021-01-23 08:38

    if you have this "very" simple structure

    
    
    
    
    

    you can

    $(':checkbox').change(function(){
      $(this).next().attr('disabled',!this.checked);
    })​;
    

    here is a demo

    but then I know you don't have that "very" simple structure so, read the following and get the idea from above...

    1. traversing
    2. selectors

    If you can provide the structure of your html, much better...

提交回复
热议问题