HTML form readonly SELECT tag/input

前端 未结 30 2787
陌清茗
陌清茗 2020-11-22 08:28

According to HTML specs, the select tag in HTML doesn\'t have a readonly attribute, only a disabled attribute. So if you want to keep

30条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-22 09:07

    I know that it is far too late, but it can be done with simple CSS:

    select[readonly] option, select[readonly] optgroup {
        display: none;
    }
    

    The style hides all the options and the groups when the select is in readonly state, so the user can not change his selection.

    No JavaScript hacks are needed.

提交回复
热议问题