Can HTML checkboxes be set to readonly?

前端 未结 30 1645
無奈伤痛
無奈伤痛 2020-11-22 08:39

I thought they could be, but as I\'m not putting my money where my mouth was (so to speak) setting the readonly attribute doesn\'t actually seem to do anything.

I\'d

30条回答
  •  名媛妹妹
    2020-11-22 09:00

    I would use the readonly attribute

    
    

    Then use CSS to disable interactions:

    input[type='checkbox'][readonly]{
        pointer-events: none;
    }
    

    Note that using the pseudo-class :read-only doesn't work here.

    input[type='checkbox']:read-only{ /*not working*/
        pointer-events: none;
    }
    

提交回复
热议问题