HTML form readonly SELECT tag/input

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

    If you disable a form field, this won't be sent when form is submitted. So if you need a readonly that works like disabled but sending values do this :

    After any change in readonly properties of an element.

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

提交回复
热议问题