Event Listener valid for HTML5 forms

前端 未结 4 1521
半阙折子戏
半阙折子戏 2020-12-18 19:41
  1. New on HTML5 there\'s an \"invalid\" event, to which you can add a listener:

    document.addEventListener(\'invalid\', function(e){
       var element = $(         
    
    
            
4条回答
  •  春和景丽
    2020-12-18 20:08

    Have you tried using :valid to give an indicator as to whether a field is valid. and having forms that are invalid just keep their default styling.

    Then calling form.checkValidity() in the submit handler? (The browser should then tell the end-user which form element is not valid).

提交回复
热议问题