这是我用Firebug在Firefox中找到的。

Values of disabled inputs will not be submitted

在其他浏览器中也一样吗?

如果有,原因是什么?


当前回答

是的,所有浏览器都不应该提交禁用的输入,因为它们是只读的。

更多信息(第17.12.1节)

Attribute definitions disabled [CI] When set for a form control, this Boolean attribute disables the control for user input. When set, the disabled attribute has the following effects on an element: Disabled controls do not receive focus. Disabled controls are skipped in tabbing navigation. Disabled controls cannot be successful. The following elements support the disabled attribute: BUTTON, INPUT, OPTGROUP, OPTION, SELECT, and TEXTAREA. This attribute is inherited but local declarations override the inherited value. How disabled elements are rendered depends on the user agent. For example, some user agents "gray out" disabled menu items, button labels, etc. In this example, the INPUT element is disabled. Therefore, it cannot receive user input nor will its value be submitted with the form. <INPUT disabled name="fred" value="stone"> Note. The only way to modify dynamically the value of the disabled attribute is through a script.

其他回答

选择控件仍然是可点击的,即使在只读attrib

如果你仍然想禁用控件,但你想发布它的值。 您可以考虑创建一个隐藏字段。具有与控件相同的值。

然后创建一个jquery,选择更改

$('#your_select_id').change(function () {
    $('#your_hidden_selectid').val($('#your_select_id').val());
});

它们不会被提交,因为W3C规范是这么说的。

17.13.2成功控制 一个成功的控件是“有效的”提交。(剪) 被禁用的控件无法成功执行。

换句话说,规范说禁用的控件被认为是无效的。

禁用的控件不能成功,成功的控件“有效”提交。 这就是禁用控件不能与表单一起提交的原因。

是的,所有浏览器都不应该提交禁用的输入,因为它们是只读的。

更多信息(第17.12.1节)

Attribute definitions disabled [CI] When set for a form control, this Boolean attribute disables the control for user input. When set, the disabled attribute has the following effects on an element: Disabled controls do not receive focus. Disabled controls are skipped in tabbing navigation. Disabled controls cannot be successful. The following elements support the disabled attribute: BUTTON, INPUT, OPTGROUP, OPTION, SELECT, and TEXTAREA. This attribute is inherited but local declarations override the inherited value. How disabled elements are rendered depends on the user agent. For example, some user agents "gray out" disabled menu items, button labels, etc. In this example, the INPUT element is disabled. Therefore, it cannot receive user input nor will its value be submitted with the form. <INPUT disabled name="fred" value="stone"> Note. The only way to modify dynamically the value of the disabled attribute is through a script.

<input type="text" disabled /> 

使用readonly代替这个禁用

<input type="text" readonly />