submit disabled fields

后端 未结 8 1607
无人及你
无人及你 2020-12-03 04:34

I know the defined behavior for web forms is to not submit disabled fields... but that\'s not the definition I want. I want to use ajax to post the form and I want it to ge

8条回答
  •  执念已碎
    2020-12-03 05:13

    You can make your fields readonly, this will disallow changes to the value of your controls.

    Edit: You could easily write a "serializeDisabled" function, iterating over the disabled form elements which have a name attribute and using the jQuery.param function at the end, to generate the serialized string:

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

提交回复
热议问题