Javascript 输入文本时文本区域中背景图像消失

Javascript 输入文本时文本区域中背景图像消失,javascript,html,css,Javascript,Html,Css,我想在HTML中设置一个图像作为textarea标记的背景,然后在用户输入一些文本时使其消失,同时也有一个新的背景(在本例中只是一种颜色)。我所期望的行为与占位符属性类似,只是对于背景。我还发现使用jQuery是可行的,但是我没有使用它 index.html: <html> <head> <link rel="stylesheet" href="style.css"> <body> <

我想在HTML中设置一个图像作为textarea标记的背景,然后在用户输入一些文本时使其消失,同时也有一个新的背景(在本例中只是一种颜色)。我所期望的行为与占位符属性类似,只是对于背景。我还发现使用jQuery是可行的,但是我没有使用它 index.html:

<html>
  <head>
  <link rel="stylesheet" href="style.css">
  <body>
    <textarea id="code"></textarea>
  </body>
#代码{
颜色:白色;
背景色:黑色;
}
#代码:显示占位符{
背景:url(https://leanfrontiers.com/wp-content/uploads/2018/12/logo-placeholder-png.png)中心不重复;
}
#代码:非(:显示占位符){
背景色:红色;
}
#代码{
颜色:白色;
背景色:黑色;
}
#代码:显示占位符{
背景:url(https://leanfrontiers.com/wp-content/uploads/2018/12/logo-placeholder-png.png)中心不重复;
}
#代码:非(:显示占位符){
背景色:红色;
}
试试这个
#code:active{background:none;}

试试这个
#code:active{background:none;}

谢谢你的回答,但@Ruudi的答案有效。另外,我认为在我写这段代码之前,背景会消失,但是一旦我激活了文本区域。谢谢你的回答,但是@Ruudi的一个有效。我还认为,在我写这段代码之前,背景会消失,但一旦我激活了文本区域。
#code {
  color: white;
  background-color: black;
  background: url(logo.png) center center no-repeat;
}