Firefox 4:有没有办法删除所需表单输入中的红色边框?
当在表单字段中定义 required 时,Firefox 4 会自动显示该元素的红色边框,甚至在用户点击提交按钮之前也是如此。
<input type="text" name="example" value="This is an example" required />
我认为这对用户来说是令人不安的,因为他/她一开始就没有犯错误。
我想隐藏初始状态的红色边框,但如果缺少标记为必填的字段,则当用户点击发送按钮时显示它。
我从新的伪选择器中查看了 :required
和 :invalid
,但更改是在验证之前和之后进行的。 (来自 Firefox 4 必需的输入表单红色边框/轮廓)
有没有办法在用户提交表单之前禁用红色边框,并在缺少某些字段时显示它?
When required is defined in a form field, Firefox 4 automatically shows a red border to this element, even BEFORE the user hits the submit button.
<input type="text" name="example" value="This is an example" required />
I think this is disturbing for the user as he/she asn't made mistakes at the beginning.
I wnat to hide that red border for the initial state, but show it when the user hits the send button if there is a missing field marked as required.
I looked at :required
and :invalid
from new pseudo selector, but the changes are for before AND after the validation. (from Firefox 4 Required input form RED border/outline)
Is there a way to disable the red border before the user submits the form, and show it if there is some missing fields ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
这有点棘手,但我已经设置了这个例子: http://jsfiddle.net/c5aTe/ 这对我有用。基本上,这个技巧似乎是绕过无效的占位符文本。否则你应该能够这样做:
或类似的东西...
但是因为FF4决定验证你的占位符文本(不知道为什么...)小提琴中的解决方案(小黑客 - 使用
!important
) 是必需的。编辑
Doh!! - 我觉得很傻。我已经更新了我的小提琴: http://jsfiddle.net/c5aTe/2/ - 你可以使用
:focus
伪类来使元素在用户键入时保持有效样式。如果项目失去焦点时内容无效,这仍然会以红色突出显示,但我认为您对设计的行为只能做这么多...HTH :)
接受后编辑:应
OP要求的示例摘要(注意前两个仅设计用于 FF4 - 不是 Chrome)
This was a little tricky but I've set up this exmaple: http://jsfiddle.net/c5aTe/ which is working for me. Basically the trick seems to be getting around having placeholder text which is invalid. Otherwise you should be able do this:
or something similar...
BUT since FF4 decides to validate your placeholder text (no idea why...) the solution in the fiddle (little hacky - uses
!important
) is required.EDIT
Doh!! - I feel well silly. I've updated my fiddle: http://jsfiddle.net/c5aTe/2/ - you can use the
:focus
pseudo class to keep the element styled as if valid while the user is typing. This will still highlight in red if the content is invalid when the item loses focus but I think there is only so much you can do with the designed behaviour...HTH :)
EDIT after acceptance:
Summary of examples at OP's request (note the first two are only designed for FF4 - not Chrome)
从 Firefox 26 开始,用于识别无效必填字段的实际 CSS 如下(来自 forms.css):
为了在其他浏览器中复制,我使用:
我使用了像素设置,但我永远不会猜到 1.5px无需查看moz源代码。
要禁用它,您可以使用:
As of Firefox 26, the actual CSS used to identify invalid required fields is as follows (comes from forms.css):
To replicate in other browsers, I use:
I played around with the pixel settings but I never would have guessed the 1.5px without looking at moz source.
To disable it, you can use:
尝试:
Try:
这是一个对我有用的非常简单的解决方案。我基本上将丑陋的红色更改为非常漂亮的蓝色,这是非必填字段的标准颜色,也是网络约定:
Here is a very easy solution that worked for me. I basically changed the ugly red into a very nice blue, which is the standard color for non-required fields, and a web convention:
这对我来说效果很好:
This worked well for me:
请尝试这个,
$("form").attr("novalidate",true);
对于您的全局 .js 文件或标头部分中的表单。
Please try this,
$("form").attr("novalidate",true);
for your form in your global .js file or in header section.
我发现至少大部分解决这个问题的方法是:
这样,输入字段以漂亮的蓝色轮廓开始,但是一旦用户输入一个字符,它就会设置为必填(所以如果您输入一个字符然后退格,红色边界就在那里)。在这种情况下,用户可能会跳过输入,因此如果执行此操作,请确保进行后端验证。
A way I found to at least mostly fix the issue is:
That way, the input field starts out with that nice blue outline, but once the user enters a character it's set to required (so if you enter a character then backspace, the red border is there). In this case it is possible for a user to skip the input, so make sure to put backend validation in place if you do this.