要选择只读元素,请使用CSS:read-only选择器。
您可以尝试运行以下代码来实现:read-only选择器
<!DOCTYPE html> <html> <head> <style> input:read-only { background-color: blue; color: white; } </style> </head> <body> <form> Subject: <input type = "text" name = "subject" value = "Maths"><br> Student: <input type = "text" name = "student" readonly value = "Amit"><br> </form> </body> </html>