问题描述
表单的HTML标准似乎是这样的,禁用的输入元素不会影响表单名称/值集合。
有没有办法绕过这个?我需要能够打开和关闭禁用,但仍然返回提交表单时的值。
我意识到我可以使用JavaScript来复制值提交表单之前隐藏的输入,但我不想。有没有更清晰的方式?
我使用的是ASP.NET,并不重要。
readOnly
标志而不是 disabled
。 < input type =text只读字段不能由用户编辑,但仍然会以表单提交。 value =blahreadonly =true/>
The HTML standard for forms appears to be such that disabled input elements do not contribute to the form name/value collection.
Is there ANY way to get around this? I need to be able to toggle disable on and off but still return whatever the value is when the form is submitted.
I realize that I can use JavaScript to copy the value to a hidden input before the form is submitted, but I would prefer not to. Is there a cleaner way?
I'm using ASP.NET, not that that matters.
You should use the readOnly
flag rather than disabled
. Read-only fields cannot be edited by the user, but are still submitted with the form.
<input type="text" value="blah" readonly="true"/>
这篇关于如何从禁用的< input>获取表单值?元件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!