Validation in HTML5. :invalid classe after submit

前端 未结 9 2487
清歌不尽
清歌不尽 2021-02-18 14:11

I\'m building a form and I want to use the :invalid selector to give the \"required\" input fields a red border if the user presses submit without filling them, but

9条回答
  •  暖寄归人
    2021-02-18 14:30

    Another way is to add a hide-hints class to the inputs with JavaScript on load. When a user modifies a field you remove the class.

    In your CSS you then apply styling to input:not(.hide-hints):invalid. This means the error styling will be shown for users without JavaScript as well.

提交回复
热议问题