使用CSS:必需的选择器来为具有<required>属性的<input>元素设置样式。
您可以尝试运行以下代码来实现:required Selector
<!DOCTYPE html> <html> <head> <style> input:required { background-color: orange; } </style> </head> <body> <form> Subject: <input type = "text" name = "subject" value = "C++"><br> Student: <input type = "text" name = "student" value = "Amit" required><br> </form> </body> </html>