使用CSS:有效选择器为所有<input>元素设置有效值的样式。
您可以尝试运行以下代码来实现:valid选择器
<!DOCTYPE html> <html> <head> <style> input:valid { background: red; color: white; } </style> </head> <body> <h2>Heading</h2> <input type = "email" value = "amit@example.com"> <p>The style (red color background) appears if you type a relevant/ valid email address.</p> </body> </html>