提交禁用的字段 [英] submit disabled fields

查看:356
本文介绍了提交禁用的字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道web表单的定义行为是不提交禁用的字段......但这不是我想要的定义。我想使用ajax发布表单,并且我希望它能够获取所有字段,即使它们被禁用。我不想建立一个解决方法,让字段看起来被禁用......或者必须在启用字段的地方进行破解 - > post - > disable。

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 get all fields, even if they are disabled. I don't want to build a workaround where I make the field "look disabled"... or have to hack it where I enable the fields -> post -> disable.

是否有可能使ajaxSubmit()或serialize()获取禁用的字段,因为它正在移动DOM并获取值?还是有另一个序列化插件可以做到这一点?还是有人有一个模组,我可以使这些插件之一,使其工作?

is it possible to make ajaxSubmit() or serialize() grab the disabled fields as it's moving through the DOM and grabbing values? or is there another serialize plugin out there that can do this? or does someone have a mod I can make to one of these plugins to make it work?

或者我注定要破解它?

推荐答案

您可以让您的字段只读,这将不允许更改您的控件的值。

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

编辑:您可以轻松地编写一个 serializeDisabled 函数,迭代具有name属性的禁用表单元素并使用

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);

这篇关于提交禁用的字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆