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

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

问题描述

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

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"函数,迭代具有名称属性的禁用表单元素并使用jQuery.param 函数最后,生成序列化字符串:

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天全站免登陆