禁用的表单字段未提交数据 [英] Disabled form fields not submitting data

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

问题描述

有什么方法(使用属性标志或类似的东西)可以启用禁用提交数据的表单字段?

Is there any way (with a attribute flag or something like that) to enable form fields that are disabled to submit data?

或者,如果这是不可能的,有没有办法阻止字段使用 css 或任何其他属性进行编辑而不隐藏它们?

Or, if that's not possible, is there any way to block fields from editing with css or any other attribute than disabled without hiding them?

我目前的特殊情况是数据集的标识符,该标识符应显示在表单中(不可编辑)-如果没有更好的解决方案,我想除了禁用的字段外,我还将使用隐藏字段保存实际值,禁用显示它的值.

My special case at the moment is an identifier for a data-set that should be shown in the form (uneditable) - if there is no better solution I think i'll use a hidden field in addition to the disabled one to hold the actual value with the disabled one showing it.

推荐答案

正如已经提到的:READONLY 不适用于 code> 和 .

As it was already mentioned: READONLY does not work for <input type='checkbox'> and <select>...</select>.

如果您有一个 Form 禁用复选框/选择并且需要提交它们,您可以使用 jQuery:

If you have a Form with disabled checkboxes / selects AND need them to be submitted, you can use jQuery:

$('form').submit(function(e) {
    $(':disabled').each(function(e) {
        $(this).removeAttr('disabled');
    })
});

此代码在提交时从所有元素中删除 disabled 属性.

This code removes the disabled attribute from all elements on submit.

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

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