HTML form readonly SELECT tag/input

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

    You can re-enable the select object on submit.

    EDIT: i.e., normally disabling the select tag (with the disabled attribute) and then re-enabling it automatically just before submiting the form:

    Example with jQuery:

    • To disable it:

      $('#yourSelect').prop('disabled', true);
      
    • To re-enable it before submission so that GET / POST data is included:

      $('#yourForm').on('submit', function() {
          $('#yourSelect').prop('disabled', false);
      });
      

    In addition, you could re-enable every disabled input or select:

    $('#yourForm').on('submit', function() {
        $('input, select').prop('disabled', false);
    });
    

提交回复
热议问题