HTML5 必需的输入样式 [英] HTML5 Required input styling

查看:48
本文介绍了HTML5 必需的输入样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 HTML 5 中,我们可以将输入标记为 required,然后使用 CSS 中的 [required] 伪选择器选择它们.但我只想在他们尝试提交表单而不填写所需元素时为其设置样式.有这个选择器吗?弹出的小消息框呢?

In HTML 5, we can mark inputs as required and then select them with the [required] pseudo-selector in CSS. But I only want to style them when they try to submit the form without filling out a required element. Is there a selector for this? How about for the little message box which pops up?

推荐答案

是的,正如 SLaks 所说,没有 CSS 选择器可以做到这一点.我怀疑这是否会在 CSS 的范围内,因为 CSS 需要检查输入的内容.

Yeah as SLaks said there is no CSS selector to do this. I would doubt this will ever be in the scope of CSS because CSS would need to check the contents of an input.

您最好的选择仍然是在单击按钮时调用 javascript 验证函数,而不是实际提交表单.然后检查 [必填] 字段是否有适当的内容,并提交表单或突出显示未填写的必填字段.

Your best option, still, is probably to call a javascript validation function when clicking a button, rather than actually submitting the form. Then checking the [required] fields for appropriate content and either submitting the form or highlighting the required fields that were not filled in.

JQuery 有一些不错的插件可以帮你解决这个问题http://docs.jquery.com/Plugins/validation

JQuery has some nice plugins that take care of this for you http://docs.jquery.com/Plugins/validation

这篇关于HTML5 必需的输入样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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