这在浏览器中意味着什么:“将不会提交禁用输入的值”?
这是我在 Firefox 中通过 Firebug 发现的。
Values of disabled inputs will not be submitted
在其他浏览器中也是这样吗?
如果是这样,原因是什么?
This is what I found by Firebug in Firefox.
Values of disabled inputs will not be submitted
Is it the same in other browsers?
If so, what's the reason for this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(9)
disabled
输入将不会提交数据。使用
readonly
属性:来源在这里
disabled
input will not submit data.Use the
readonly
attribute:Source here
是的,所有浏览器都不应提交禁用的输入。
更多信息(第 17.12.1 节)
Yes, all browsers should not submit the disabled inputs.
More information (section 17.12.1)
您可以使用三种方式来模拟禁用:
HTML:
readonly
属性(以便输入中存在的值可以在表单提交时使用。用户也无法更改输入值)< /p>CSS:
'pointer -events':'none'
(阻止用户点击输入)HTML:
tabindex="-1"
(阻止用户从键盘导航到输入)You can use three things to mimic disabled:
HTML:
readonly
attribute (so that the value present in input can be used on form submission. Also the user can't change the input value)CSS:
'pointer-events':'none'
(blocking the user from clicking the input)HTML:
tabindex="-1"
(blocking the user to navigate to the input from the keyboard)它们不会被提交,因为这就是它在W3C 规范。
换句话说,规范规定禁用的控件将被视为提交无效。
They don't get submitted, because that's what it says in the W3C specification.
In other words, the specification says that controls that are disabled are considered invalid for submission.
而不是这个禁用使用只读
instead of this disabled use readonly
有两个属性,即
readonly
和disabled
,可以使输入成为半只读。但它们之间有一个微小的区别。readonly
属性使您的输入文本被禁用,用户无法再更改它。disabled
属性不仅会使您的输入文本禁用(不可更改),而且无法提交。jQuery 方法(1):
jQuery 方法(2):
JavaScript 方法:
PS
disabled
和readonly
是标准的 html 属性。prop
随jQuery 1.6
引入。There are two attributes, namely
readonly
anddisabled
, that can make a semi-read-only input. But there is a tiny difference between them.readonly
attribute makes your input text disabled, and users are not able to change it anymore.disabled
attribute make your input-text disabled(unchangeable) but also cannot it be submitted.jQuery approach (1):
jQuery approach (2):
JavaScript approach:
PS
disabled
andreadonly
are standard html attributes.prop
introduced withjQuery 1.6
.禁用
控件无法成功,成功的控件对于提交来说是“有效”的。这就是禁用的控件不随表单提交的原因。
Disabled
controls cannot be successful, and a successful control is "valid" for submission.This is the reason why disabled controls don't submit with the form.
即使在只读属性上,选择控件仍然可单击
如果您仍想禁用该控件但希望发布其值,则 。
您可以考虑创建一个隐藏字段。与您的控件具有相同的值。
然后创建一个jquery,选择更改
select controls are still clickable even on readonly attrib
if you want to still disable the control but you want its value posted.
You might consider creating a hidden field. with the same value as your control.
then create a jquery, on select change
这是解决方案,仍然使用禁用的属性。
首先禁用加载时的输入。
提交时启用所有这些。这将确保所有内容都已发布
Here's the Solution and still using disabled property.
First disable your inputs on load.
on submit enable all of them. this will assure everything is posted