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

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

问题描述

在HTML 5中,我们可以将输入标记为 required ,然后使用 [required] CSS中的选择器。但我只想在他们尝试提交表单而不填写必需的元素时对它们进行样式化。有这样的选择器吗?

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有一些不错的插件this for you
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天全站免登陆