How to style a disabled checkbox?

后端 未结 9 764
旧巷少年郎
旧巷少年郎 2021-01-07 16:32

Do you know how I could style a checkbox when it is disabled?

E.g.:



        
9条回答
  •  误落风尘
    2021-01-07 16:53

    Use the attribute selector in the css

    input[disabled]{
      outline:1px solid red; // or whatever
    }
    

    for checkbox exclusively use

    input[type=checkbox][disabled]{
      outline:1px solid red; // or whatever
    }
    

    $('button').click(function() {
      const i = $('input');
    
      if (i.is('[disabled]'))
        i.attr('disabled', false)
      else
        i.attr('disabled', true);
    })
    input[type=checkbox][disabled] {
      outline: 2px solid red;
    }
    
    
    
    

提交回复
热议问题