HTML form readonly SELECT tag/input

前端 未结 30 2917
陌清茗
陌清茗 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:09

    Simple jQuery solution

    Use this if your selects have the readonly class

    jQuery('select.readonly option:not(:selected)').attr('disabled',true);
    

    Or this if your selects have the readonly="readonly" attribute

    $('select[readonly="readonly"] option:not(:selected)').attr('disabled',true);
    

提交回复
热议问题