使用CSS:required选择器设置& lt; input& gt;的样式。具有“必需”属性的元素。您可以尝试运行以下代码来实现:required选择器:
<!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>