是的,HTML5验证对于验证表单也非常有用。现在,您不需要JavaScript即可进行客户端验证,例如永远不会提交空文本框,因为HTML5引入了一个称为required的新属性。
让我们看一个例子-
<!DOCTYPE HTML> <html> <body> <form action = "/cgi-bin/html5.cgi" method = "get"> Enter email : <input type = "text" name = "newinput" required/> <p>Try to submit using Submit button</p> <input type = "submit" value = "submit" /> </form> </body> </html>