values of disabled inputs will not be submitted?

2018-12-31 15:50发布

This is what I found by fireBug in firefox.

Is it the same in other browsers?

If so, what's the reason for this?

5条回答
素衣白纱
2楼-- · 2018-12-31 16:14

disabled input will not submit data.

Use the readonly attribute:

<input type="text" readonly />

Source here

查看更多
牵手、夕阳
3楼-- · 2018-12-31 16:14

Disabled controls cannot be successful, and a successful control is "valid" for submission. This is the reason why disabled controls dont submit with the form.

查看更多
无色无味的生活
4楼-- · 2018-12-31 16:27

Can use three things to mimic disabled:

  1. HTML: readonly attribute (so that the value present in input can be used on form submission. Also user can't change the input value)

  2. CSS: 'pointer-events':'none' (blocking user from clicking the input)

  3. HTML: tabindex="-1" (blocking user to navigate to the input from keyboard)

查看更多
冷夜・残月
5楼-- · 2018-12-31 16:29

Yes, All browsers do not should not submit the disabled inputs, as they are read-only.

More info (section 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.

查看更多
皆成旧梦
6楼-- · 2018-12-31 16:33

They don't get submitted because that's what it says in the W3C spec.

17.13.2 Successful controls

A successful control is "valid" for submission. [snip]

  • Controls that are disabled cannot be successful.

In other words, the spec says that controls that are disabled are considered invalid and should not be submitted.

查看更多
登录 后发表回答