<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
input :focus{
background-color: aquamarine;
}
</style>
</head>
<body>
<input type="text" placeholder="hello">
</body>
</html>
input后面的空格去掉
js的话,在background函数里面设置样式
<input type="text" placeholder="hello" onfocus="background()">
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
input {
border:1px solid red;
background-color: aquamarine;
}
</style>
</head>
<body>
<input type="text" placeholder="hello">
</body>
</html>
央视选择器不对,input:focus 的作用是选择获得焦点的输入字段,并设置其样式。也就是当你点击文本框后的样式效果。另外使用input :focus中间是没有空格的。