Can HTML checkboxes be set to readonly?

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

    If you want them to be submitted to the server with form but be not interacive for user, you can use pointer-events: none in css (works in all modern browsers except IE10- and Opera 12-) and set tab-index to -1 to prevent changing via keyboard. Also note that you can't use label tag as click on it will change the state anyway.

    input[type="checkbox"][readonly] {
      pointer-events: none !important;
    }
    
    td {
      min-width: 5em;
      text-align: center;
    }
    
    td:last-child {
      text-align: left;
    }
    usual readonly disabled
    works
    also works
    broken - don't use label tag

提交回复
热议问题