是否显示:none禁用< input&gt ;? [英] Does display: none disable an <input>?

查看:41
本文介绍了是否显示:none禁用< input&gt ;?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我之前经历过以下现象:如果< input> 标记具有CSS属性 display:none ,则其值不会与父项一起提交形式.我现在很奇怪,这种行为很有帮助!

I've experienced before the phenomenon that if an <input> tag has the CSS property display: none, then its value isn't submitted with its parent form. I'm now in the curious situation where that behaviour is helpful!

我可以依靠 display:none 来防止在提交表单时包含输入内容吗?或者从技术上讲,这是对规范的偏离吗?

Can I rely on display: none to prevent inclusion of an input when its form is submitted, or is it technically a deviation from the spec?

到目前为止,答案都集中在其他方法上,以及后端验证的必要性.我知道这是一种有点奇怪的处理方式,而且我知道我需要在后端进行验证.我已经是;只是我要返回的参数格式使我处理的一个特定方面有些棘手.

The answers so far have all focussed on other ways of doing this, and the necessity of back-end validation, so let me be clear; I know this is a slightly odd way of doing things, and I know I need to validate on the back end. I already am; it's just that the format of the parameter I'm getting back makes one particular aspect of my processing slightly tricky.

尝试更清楚地重新表述问题:是否存在可靠的CSS内方式来防止输入包含在表单中?似乎是在设置字段的显示 none 可行,但是我无法确定是否应该工作.我不在乎用户是否可能编辑前端HTML/CSS,因为我会在后端捕获它.您可能会假设一个非恶意用户.

As an attempt to rephrase the question slightly more clearly: Is there a reliable in-CSS way to prevent an input from being included with its form? It appears that setting a field's display to none works, but I haven't been able to tell whether it should work. I don't care about users potentially editing the front end HTML / CSS, because I will catch that on the back-end. You may assume a non-malicious user.

推荐答案

否.您绝对应该使用 disabled 属性.

No. You should definitely use the disabled attribute.

使用HTML5,当必填字段设置为 display:none

With HTML5, some browsers(i.e. Chrome) will even prevent you from submitting the form when a required field was set to display:none

这篇关于是否显示:none禁用&lt; input&gt ;?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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