Can HTML checkboxes be set to readonly?

前端 未结 30 2061
無奈伤痛
無奈伤痛 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:05

    This is a checkbox you can't change:

    
    

    Just add disabled="disabled" as an attribute.


    Edit to address the comments:

    If you want the data to be posted back, than a simple solutions is to apply the same name to a hidden input:

    
    
    

    This way, when the checkbox is set to 'disabled', it only serves the purpose of a visual representation of the data, instead of actually being 'linked' to the data. In the post back, the value of the hidden input is being sent when the checkbox is disabled.

提交回复
热议问题