Disabled fields not picked up by serializeArray

前端 未结 4 956
伪装坚强ぢ
伪装坚强ぢ 2020-12-17 09:20

(Question updated to reflect real issue)

I just realized that serializeArray is not fetching content from disabled fields.

A set of

4条回答
  •  一生所求
    2020-12-17 09:50

    Try this

    var data = $('form').serializeAllArray();
    

    And here is the small plugin that is used

    (function ($) {
      $.fn.serializeAllArray = function () {
        var obj = {};
    
        $('input',this).each(function () { 
            obj[this.name] = $(this).val(); 
        });
        return $.param(obj);
      }
    })(jQuery);
    

    You can also try enabling all your element's just to serialize them and then disable them after serializing.

    var myform = $('#form');
    var disabled = myform.find(':input:disabled').removeAttr('disabled');
    var serialized = myform.serializeArray();
    disabled.attr('disabled','disabled');
    

提交回复
热议问题